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: scan brc-20 blocks using a cursor #251

Merged
merged 2 commits into from
Oct 11, 2023
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
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
Loading