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
Signed-off-by: Eric <eric.warehime@gmail.com>
  • Loading branch information
dydxwill authored and Eric-Warehime committed Mar 12, 2024
1 parent 735d9a8 commit 41de83e
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 41de83e

Please sign in to comment.