Skip to content

Commit

Permalink
fixed handling cache clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
zavelevsky committed May 31, 2024
1 parent 3fa7e28 commit b9dbd6b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/chain-cache/ChainCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class ChainCache extends (EventEmitter as new () => TypedEventEmitter<Cac
logger.debug('Cache miss for pair', token0, token1, 'resolved');
}

public clear(): void {
public clear(silent: boolean = false): void {
const pairs = Object.keys(this._strategiesByPair).map(fromPairKey);
this._strategiesByPair = {};
this._strategiesById = {};
Expand All @@ -183,7 +183,9 @@ export class ChainCache extends (EventEmitter as new () => TypedEventEmitter<Cac
this._latestTradesByPair = {};
this._latestTradesByDirectedPair = {};
this._blocksMetadata = [];
this.emit('onPairDataChanged', pairs);
if (!silent) {
this.emit('onPairDataChanged', pairs);
}
}

//#region public getters
Expand Down
3 changes: 2 additions & 1 deletion src/chain-cache/ChainSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export class ChainSync {
`startDataSync - cache is too old: current block ${blockNumber}, cache block ${latestBlockInCache}`,
arguments
);
// cache starts from scratch so we want to avoid getting events from the beginning of time
// cache is too old so we want to clear it and avoid getting events from the beginning of time
this._chainCache.clear(true);
this._chainCache.applyBatchedUpdates(blockNumber, [], [], [], [], []);
}

Expand Down

0 comments on commit b9dbd6b

Please sign in to comment.