Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit 33f8cb2

Browse files
authored
fix: batch location pointer inserts (#308)
* fix: batch location pointer inserts * fix: batch 8k
1 parent 1b8e110 commit 33f8cb2

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/pg/pg-store.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -547,19 +547,23 @@ export class PgStore extends BasePgStore {
547547
sat_coinbase_height = EXCLUDED.sat_coinbase_height,
548548
updated_at = NOW()
549549
`;
550-
const pointers = await sql<DbLocationPointerInsert[]>`
551-
INSERT INTO locations ${sql(locationInserts)}
552-
ON CONFLICT ON CONSTRAINT locations_inscription_id_block_height_tx_index_unique DO UPDATE SET
553-
genesis_id = EXCLUDED.genesis_id,
554-
block_hash = EXCLUDED.block_hash,
555-
tx_id = EXCLUDED.tx_id,
556-
address = EXCLUDED.address,
557-
value = EXCLUDED.value,
558-
output = EXCLUDED.output,
559-
"offset" = EXCLUDED.offset,
560-
timestamp = EXCLUDED.timestamp
561-
RETURNING inscription_id, id AS location_id, block_height, tx_index, address
562-
`;
550+
const pointers: DbLocationPointerInsert[] = [];
551+
for (const batch of batchIterate(locationInserts, 8000))
552+
pointers.push(
553+
...(await sql<DbLocationPointerInsert[]>`
554+
INSERT INTO locations ${sql(batch)}
555+
ON CONFLICT ON CONSTRAINT locations_inscription_id_block_height_tx_index_unique DO UPDATE SET
556+
genesis_id = EXCLUDED.genesis_id,
557+
block_hash = EXCLUDED.block_hash,
558+
tx_id = EXCLUDED.tx_id,
559+
address = EXCLUDED.address,
560+
value = EXCLUDED.value,
561+
output = EXCLUDED.output,
562+
"offset" = EXCLUDED.offset,
563+
timestamp = EXCLUDED.timestamp
564+
RETURNING inscription_id, id AS location_id, block_height, tx_index, address
565+
`)
566+
);
563567
await this.updateInscriptionRecursions(reveals);
564568
if (transferredOrdinalNumbers.length)
565569
await sql`

0 commit comments

Comments
 (0)