Skip to content

Commit

Permalink
fix: scan brc-20 blocks using a cursor (#251)
Browse files Browse the repository at this point in the history
* fix: scan brc-20 blocks using a cursor

* fix: bump up to 100k events per chunk
  • Loading branch information
rafaelcr committed Oct 11, 2023
1 parent 950b07d commit a1bf4b4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/pg/brc20/brc20-pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Brc20PgStore extends BasePgStoreModule {
for (let blockHeight = startBlock; blockHeight <= endBlock; blockHeight++) {
logger.info(`Brc20PgStore scanning block ${blockHeight}`);
await this.sqlWriteTransaction(async sql => {
const block = await sql<DbBrc20ScannedInscription[]>`
const cursor = sql<DbBrc20ScannedInscription[]>`
SELECT
EXISTS(SELECT location_id FROM genesis_locations WHERE location_id = l.id) AS genesis,
l.id, l.inscription_id, l.block_height, l.tx_id, l.tx_index, l.address
Expand All @@ -57,8 +57,10 @@ export class Brc20PgStore extends BasePgStoreModule {
AND i.number >= 0
AND i.mime_type IN ('application/json', 'text/plain')
ORDER BY tx_index ASC
`;
await this.insertOperations(block);
`.cursor(100_000);
for await (const chunk of cursor) {
await this.insertOperations(chunk);
}
});
}
}
Expand Down

0 comments on commit a1bf4b4

Please sign in to comment.