diff --git a/packages/core-database/src/repositories/abstract-repository.ts b/packages/core-database/src/repositories/abstract-repository.ts index 2d6382ddbd..03d105a9d1 100644 --- a/packages/core-database/src/repositories/abstract-repository.ts +++ b/packages/core-database/src/repositories/abstract-repository.ts @@ -142,7 +142,13 @@ export abstract class AbstractRepository extends private addOrderBy(queryBuilder: SelectQueryBuilder, sorting: Contracts.Search.Sorting): void { if (sorting.length) { - const column = this.queryHelper.getColumnName(this.metadata, sorting[0].property); + let column = this.queryHelper.getColumnName(this.metadata, sorting[0].property); + + // Forces PostgreSQL query optimizer to take faster route + if (this.metadata.name === "Transaction" && column === "timestamp") { + column = `${column}+0`; + } + queryBuilder.orderBy(column, sorting[0].direction === "desc" ? "DESC" : "ASC"); for (const item of sorting.slice(1)) {