mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
fix(core): Fix sorting of executions not working on postgres and mysql (#15423)
This commit is contained in:
@@ -1048,13 +1048,32 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
|
||||
subQuery.leftJoin('execution.annotation', 'annotation');
|
||||
}
|
||||
|
||||
return this.manager
|
||||
const qb = this.manager
|
||||
.createQueryBuilder()
|
||||
.select(['e.*', 'ate.id AS "annotation_tags_id"', 'ate.name AS "annotation_tags_name"'])
|
||||
.from(`(${subQuery.getQuery()})`, 'e')
|
||||
.setParameters(subQuery.getParameters())
|
||||
.leftJoin(AnnotationTagMapping, 'atm', 'atm.annotationId = e.annotation_id')
|
||||
.leftJoin(AnnotationTagEntity, 'ate', 'ate.id = atm.tagId');
|
||||
|
||||
// Sort the final result after the joins again, because there is no
|
||||
// guarantee that the order is unchanged after performing joins. Especially
|
||||
// postgres and MySQL returned to the natural order again, listing
|
||||
// executions in the order they were created.
|
||||
if (query.kind === 'range') {
|
||||
if (query.order?.startedAt === 'DESC') {
|
||||
const table = qb.escape('e');
|
||||
const startedAt = qb.escape('startedAt');
|
||||
const createdAt = qb.escape('createdAt');
|
||||
qb.orderBy({ [`COALESCE(${table}.${startedAt}, ${table}.${createdAt})`]: 'DESC' });
|
||||
} else if (query.order?.top) {
|
||||
qb.orderBy(`(CASE WHEN e.status = '${query.order.top}' THEN 0 ELSE 1 END)`);
|
||||
} else {
|
||||
qb.orderBy({ 'e.id': 'DESC' });
|
||||
}
|
||||
}
|
||||
|
||||
return qb;
|
||||
}
|
||||
|
||||
async getAllIds() {
|
||||
|
||||
Reference in New Issue
Block a user