Skip to content

Commit 50c75e6

Browse files
authored
fix: add db indexes to optimize endpoint queries (#296)
* fix: add db indexes to optimize endpoint queries * fix: index name
1 parent 27f307e commit 50c75e6

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';
3+
4+
export const shorthands: ColumnDefinitions | undefined = undefined;
5+
6+
export function up(pgm: MigrationBuilder): void {
7+
pgm.createIndex('jobs', ['token_id']);
8+
pgm.createIndex('jobs', ['smart_contract_id']);
9+
pgm.createIndex('jobs', ['status'], { name: 'jobs_status_all_index' });
10+
pgm.createIndex('jobs', ['status', { name: 'updated_at', sort: 'ASC' }], {
11+
where: "status = 'queued'",
12+
});
13+
14+
pgm.createIndex('tokens', ['type', 'name'], { where: "type = 'ft'" });
15+
pgm.createIndex('tokens', ['type', 'symbol'], { where: "type = 'ft'" });
16+
pgm.createIndex('tokens', ['type']);
17+
18+
pgm.createIndex(
19+
'update_notifications',
20+
[
21+
'update_mode',
22+
'token_id',
23+
{ name: 'block_height', sort: 'DESC' },
24+
{ name: 'tx_index', sort: 'DESC' },
25+
{ name: 'event_index', sort: 'DESC' },
26+
],
27+
{ where: "update_mode = 'dynamic'" }
28+
);
29+
}

src/pg/pg-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,10 @@ export class PgStore extends BasePgStore {
374374
let orderBy: PgSqlQuery;
375375
switch (args.order?.order_by) {
376376
case FtOrderBy.symbol:
377-
orderBy = sql`LOWER(t.symbol)`;
377+
orderBy = sql`t.symbol`;
378378
break;
379379
default:
380-
orderBy = sql`LOWER(t.name)`;
380+
orderBy = sql`t.name`;
381381
break;
382382
}
383383
// `ORDER` statement

0 commit comments

Comments
 (0)