Skip to content

Commit

Permalink
fix: standardize insert batch size
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Feb 17, 2024
1 parent 4a81f37 commit b9b2448
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {

export const MIGRATIONS_DIR = path.join(__dirname, '../../migrations');
export const ORDINALS_GENESIS_BLOCK = 767430;
const INSERT_BATCH_SIZE = 4000;

type InscriptionIdentifier = { genesis_id: string } | { number: number };

Expand Down Expand Up @@ -133,7 +134,7 @@ export class PgStore extends BasePgStore {
currentBlockHeight: currentBlockHeight,
newBlockHeight: event.block_identifier.index,
});
for (const writeChunk of batchIterate(writes, 4000))
for (const writeChunk of batchIterate(writes, INSERT_BATCH_SIZE))
await this.insertInscriptions(writeChunk);
updatedBlockHeightMin = Math.min(updatedBlockHeightMin, event.block_identifier.index);
logger.info(
Expand Down Expand Up @@ -548,7 +549,7 @@ export class PgStore extends BasePgStore {
updated_at = NOW()
`;
const pointers: DbLocationPointerInsert[] = [];
for (const batch of batchIterate(locationInserts, 8000))
for (const batch of batchIterate(locationInserts, INSERT_BATCH_SIZE))
pointers.push(
...(await sql<DbLocationPointerInsert[]>`
INSERT INTO locations ${sql(batch)}
Expand All @@ -571,7 +572,7 @@ export class PgStore extends BasePgStore {
SET updated_at = NOW()
WHERE sat_ordinal IN ${sql(transferredOrdinalNumbers)}
`;
for (const batch of batchIterate(pointers, 8000))
for (const batch of batchIterate(pointers, INSERT_BATCH_SIZE))
await this.updateInscriptionLocationPointers(batch);
for (const reveal of reveals) {
const action =
Expand Down

0 comments on commit b9b2448

Please sign in to comment.