Skip to content

Commit

Permalink
fix: batch location pointer inserts (#308)
Browse files Browse the repository at this point in the history
* fix: batch location pointer inserts

* fix: batch 8k
  • Loading branch information
rafaelcr authored Feb 17, 2024
1 parent 1b8e110 commit 33f8cb2
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,19 +547,23 @@ export class PgStore extends BasePgStore {
sat_coinbase_height = EXCLUDED.sat_coinbase_height,
updated_at = NOW()
`;
const pointers = await sql<DbLocationPointerInsert[]>`
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<DbLocationPointerInsert[]>`
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`
Expand Down

0 comments on commit 33f8cb2

Please sign in to comment.