Skip to content

Commit

Permalink
merge: cherry-pick query optimizer workaround (#4726) (#4730)
Browse files Browse the repository at this point in the history
fix(core-database): query optimizer workaround (#4726)

* fix(core-database): query optimizer workaround

* Fix only for timestamp in transaction
  • Loading branch information
sebastijankuzner authored Nov 16, 2022
1 parent 43d3e70 commit 8a7489c
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ export abstract class AbstractRepository<TEntity extends ObjectLiteral> extends

private addOrderBy(queryBuilder: SelectQueryBuilder<TEntity>, 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)) {
Expand Down

0 comments on commit 8a7489c

Please sign in to comment.