Skip to content

Commit ca80412

Browse files
authored
[O2B-1569] Getting all runs with effective qc flags query needs to be split (#2110)
- improved loading times of page runs-per-data-pass and prevent memory crash of the process due to heavy SQL queries - use sequalize separate function to split big SQL join queries
1 parent 6ff81d8 commit ca80412

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

lib/usecases/run/GetAllRunsUseCase.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,16 @@ class GetAllRunsUseCase {
340340
}
341341

342342
if (dataPassIds) {
343+
const whereDataPassIds = dataPassIds.length === 1
344+
? { id: { [Op.eq]: dataPassIds[0] } }
345+
: { id: { [Op.in]: dataPassIds } };
343346
const runNumbers = (await RunRepository.findAll({
344347
attributes: ['runNumber'],
345348
raw: true,
346349
include: [
347350
{
348351
association: 'dataPass',
349-
where: { id: { [Op.in]: dataPassIds } },
352+
where: whereDataPassIds,
350353
},
351354
],
352355
})).map(({ runNumber }) => runNumber);
@@ -529,15 +532,17 @@ class GetAllRunsUseCase {
529532
const qcFlagsAssociationDef = {
530533
association: 'qcFlags',
531534
required: false,
535+
separate: true,
536+
order: [['from', 'ASC']],
532537
where: { [Op.and]: [
533538
{ deleted: false },
534539
sequelize.literal(`(
535-
\`qcFlags->detector\`.\`type\` not in (${detectorTypesOfNoneExportableAnonymousFlagsEscaped})
536-
OR \`qcFlags->createdBy\`.\`name\` != 'Anonymous'
540+
\`detector\`.\`type\` not in (${detectorTypesOfNoneExportableAnonymousFlagsEscaped})
541+
OR \`createdBy\`.\`name\` != 'Anonymous'
537542
)`),
538543
] },
539544
include: [
540-
{ association: 'effectivePeriods', required: true },
545+
{ association: 'effectivePeriods', required: true, separate: true },
541546
{ association: 'flagType' },
542547
{ association: 'detector', required: true },
543548
{ association: 'createdBy' },
@@ -553,13 +558,7 @@ class GetAllRunsUseCase {
553558
} else {
554559
qcFlagsAssociationDef.include.push({ association: 'dataPasses', required: false });
555560
qcFlagsAssociationDef.include.push({ association: 'simulationPasses', required: false });
556-
qcFlagsAssociationDef.where[Op.or] = [
557-
{ '$qcFlags.id$': null },
558-
{
559-
'$qcFlags.dataPasses.id$': null,
560-
'$qcFlags.simulationPasses.id$': null,
561-
},
562-
];
561+
qcFlagsAssociationDef.where[Op.and].push(sequelize.literal('(`dataPasses`.`id` IS NULL AND `simulationPasses`.`id` IS NULL)'));
563562

564563
fetchQueryBuilder.include(qcFlagsAssociationDef);
565564
}

test/public/runs/runsPerDataPass.overview.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ module.exports = () => {
407407
expect(exportContent.trim()).to.be.eql([
408408
'runNumber;CPV;VTX',
409409
'108;"";""',
410-
'107;"Good (from: 1565290800000 to: 1565359260000) | Limited Acceptance MC Reproducible (from: 1565269140000 to: 1565290800000)";""',
410+
'107;"Limited Acceptance MC Reproducible (from: 1565269140000 to: 1565290800000) | Good (from: 1565290800000 to: 1565359260000)";""',
411411
'106;"Limited Acceptance MC Reproducible (from: 1565304200000 to: 1565324200000) | Limited acceptance (from: 1565329200000 to: 1565334200000) | Bad (from: 1565339200000 to: 1565344200000)";"Good (from: 1565269200000 to: 1565304200000) | Good (from: 1565324200000 to: 1565359200000)"',
412412
].join('\r\n'));
413413
fs.unlinkSync(path.resolve(downloadPath, targetFileName));

0 commit comments

Comments
 (0)