From b9b2448a1fa1bef16f0a1eed80158ca9b8ca9133 Mon Sep 17 00:00:00 2001 From: Rafael Cardenas Date: Sat, 17 Feb 2024 17:40:46 -0600 Subject: [PATCH] fix: standardize insert batch size --- src/pg/pg-store.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pg/pg-store.ts b/src/pg/pg-store.ts index 8b7de999..2a2a397c 100644 --- a/src/pg/pg-store.ts +++ b/src/pg/pg-store.ts @@ -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 }; @@ -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( @@ -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` INSERT INTO locations ${sql(batch)} @@ -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 =