perf(core): Optimize executions filtering by metadata (#9477)

This commit is contained in:
Iván Ovejero
2024-05-22 17:20:01 +02:00
committed by GitHub
parent 09a5867707
commit 9bdc83a399
3 changed files with 53 additions and 7 deletions

View File

@@ -728,12 +728,17 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
if (startedBefore) qb.andWhere({ startedAt: lessThanOrEqual(startedBefore) });
if (startedAfter) qb.andWhere({ startedAt: moreThanOrEqual(startedAfter) });
if (metadata) {
qb.leftJoin(ExecutionMetadata, 'md', 'md.executionId = execution.id');
if (metadata?.length === 1) {
const [{ key, value }] = metadata;
for (const item of metadata) {
qb.andWhere('md.key = :key AND md.value = :value', item);
}
qb.innerJoin(
ExecutionMetadata,
'md',
'md.executionId = execution.id AND md.key = :key AND md.value = :value',
);
qb.setParameter('key', key);
qb.setParameter('value', value);
}
return qb;