From 33f8cb2576115695d8e54fcc989086afef42ddc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20C=C3=A1rdenas?= Date: Sat, 17 Feb 2024 17:19:51 -0600 Subject: [PATCH] fix: batch location pointer inserts (#308) * fix: batch location pointer inserts * fix: batch 8k --- src/pg/pg-store.ts | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/pg/pg-store.ts b/src/pg/pg-store.ts index cb16e755..ab2f8501 100644 --- a/src/pg/pg-store.ts +++ b/src/pg/pg-store.ts @@ -547,19 +547,23 @@ export class PgStore extends BasePgStore { sat_coinbase_height = EXCLUDED.sat_coinbase_height, updated_at = NOW() `; - const pointers = await sql` - INSERT INTO locations ${sql(locationInserts)} - ON CONFLICT ON CONSTRAINT locations_inscription_id_block_height_tx_index_unique DO UPDATE SET - genesis_id = EXCLUDED.genesis_id, - block_hash = EXCLUDED.block_hash, - tx_id = EXCLUDED.tx_id, - address = EXCLUDED.address, - value = EXCLUDED.value, - output = EXCLUDED.output, - "offset" = EXCLUDED.offset, - timestamp = EXCLUDED.timestamp - RETURNING inscription_id, id AS location_id, block_height, tx_index, address - `; + const pointers: DbLocationPointerInsert[] = []; + for (const batch of batchIterate(locationInserts, 8000)) + pointers.push( + ...(await sql` + INSERT INTO locations ${sql(batch)} + ON CONFLICT ON CONSTRAINT locations_inscription_id_block_height_tx_index_unique DO UPDATE SET + genesis_id = EXCLUDED.genesis_id, + block_hash = EXCLUDED.block_hash, + tx_id = EXCLUDED.tx_id, + address = EXCLUDED.address, + value = EXCLUDED.value, + output = EXCLUDED.output, + "offset" = EXCLUDED.offset, + timestamp = EXCLUDED.timestamp + RETURNING inscription_id, id AS location_id, block_height, tx_index, address + `) + ); await this.updateInscriptionRecursions(reveals); if (transferredOrdinalNumbers.length) await sql`