Skip to content

Commit

Permalink
add index to address read replica lag (dydxprotocol#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
dydxwill authored Mar 4, 2024
1 parent 5aa382f commit c84eb82
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as Knex from 'knex';

export async function up(knex: Knex): Promise<void> {
// Partial index only when `liquidity` is 'TAKER' as this index is meant to speed up the query to
// fetch all trades from the database, and we arbitrarily only use 'TAKER' fills for trades to
// avoid double counting.
// eslint-disable-next-line @typescript-eslint/quotes
await knex.raw(`
CREATE INDEX CONCURRENTLY IF NOT EXISTS "fills_clobPairId_createdAtHeight_createdAt_partial" ON "fills" ("clobPairId", "createdAtHeight", "createdAt") WHERE "liquidity" = 'TAKER';
`);
}

export async function down(knex: Knex): Promise<void> {
await knex.raw(`
DROP INDEX CONCURRENTLY IF EXISTS "fills_clobPairId_createdAtHeight_createdAt_partial";
`);
}

export const config = {
transaction: false,
};

0 comments on commit c84eb82

Please sign in to comment.