Skip to content

Commit

Permalink
perf: only try (re)creating tables once per reset/resetMetadata call (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekhmet authored Jan 31, 2025
1 parent 1644cad commit 534c54e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
5 changes: 5 additions & 0 deletions src/checkpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,13 @@ export default class Checkpoint {
*/
public async reset() {
this.log.debug('reset');
await this.store.createStore();

for (const container of this.containers.values()) {
await container.reset();
}

await this.entityController.createEntityStores(this.knex);
}

/**
Expand All @@ -168,6 +171,8 @@ export default class Checkpoint {
public async resetMetadata() {
this.log.debug('reset metadata');

await this.store.resetStore();

for (const container of this.containers.values()) {
await container.resetMetadata();
}
Expand Down
24 changes: 0 additions & 24 deletions src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,37 +330,13 @@ export class Container implements Instance {
return lastGoodBlock + 1;
}

/**
* Reset will clear the last synced block informations
* and force Checkpoint to start indexing from the start
* block.
*
* This will also clear all indexed GraphQL entity records.
*
* This should be called when there has been a change to the GraphQL schema
* or a change to the writer functions logic, so indexing will re-run from
* the starting block. Also, it should be called the first time Checkpoint
* is being initialized.
*
*/
public async reset() {
await this.store.createStore();
await this.store.setMetadata(this.indexerName, MetadataId.LastIndexedBlock, 0);
await this.store.setMetadata(this.indexerName, MetadataId.SchemaVersion, SCHEMA_VERSION);
await this.store.removeBlocks(this.indexerName);

await this.entityController.createEntityStores(this.knex);
}

/**
* Resets Checkpoint's internal tables (including checkpoints).
*
* Calling this function will cause next run of checkpoint to start syncing
* from the start, block-by-block, until new checkpoints are found.
*
*/
public async resetMetadata() {
await this.store.resetStore();
await this.store.setMetadata(this.indexerName, MetadataId.SchemaVersion, SCHEMA_VERSION);
}

Expand Down

0 comments on commit 534c54e

Please sign in to comment.