Skip to content

Commit bd1fe1a

Browse files
fix(postgres): query master for latest block to avoid replication lag (#3305)
1 parent 850c553 commit bd1fe1a

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

indexer/packages/postgres/src/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ export const DEFAULT_POSTGRES_OPTIONS : Options = config.USE_READ_REPLICA
125125
? {
126126
readReplica: true,
127127
} : {};
128+
export const USE_MASTER_POSTGRES_OPTIONS : Options = {
129+
readReplica: false,
130+
};
128131

129132
// The maximum number of parent subaccounts per address.
130133
export const MAX_PARENT_SUBACCOUNTS: number = 128;

indexer/packages/postgres/src/stores/block-table.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { logger } from '@dydxprotocol-indexer/base';
22
import { QueryBuilder } from 'objection';
33

4-
import { DEFAULT_POSTGRES_OPTIONS } from '../constants';
4+
import { DEFAULT_POSTGRES_OPTIONS, USE_MASTER_POSTGRES_OPTIONS } from '../constants';
55
import { setupBaseQuery, verifyAllRequiredFields } from '../helpers/stores-helpers';
66
import Transaction from '../helpers/transaction';
77
import BlockModel from '../models/block-model';
@@ -110,7 +110,7 @@ export async function findByBlockHeight(
110110
}
111111

112112
export async function getLatest(
113-
options: Options = DEFAULT_POSTGRES_OPTIONS,
113+
options: Options = USE_MASTER_POSTGRES_OPTIONS,
114114
): Promise<BlockFromDatabase> {
115115
const baseQuery: QueryBuilder<BlockModel> = setupBaseQuery<BlockModel>(
116116
BlockModel,

0 commit comments

Comments
 (0)