Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: batch location pointer inserts #308

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading