Skip to content

Commit 2ac02cb

Browse files
committed
avoid fetching on cache miss
1 parent b4712a6 commit 2ac02cb

File tree

6 files changed

+170
-150
lines changed

6 files changed

+170
-150
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@bancor/carbon-sdk",
33
"type": "module",
44
"source": "src/index.ts",
5-
"version": "0.0.118-DEV",
5+
"version": "0.0.119-DEV",
66
"description": "The SDK is a READ-ONLY tool, intended to facilitate working with Carbon contracts. It's a convenient wrapper around our matching algorithm, allowing programs and users get a ready to use transaction data that will allow them to manage strategies and fulfill trades",
77
"main": "dist/index.cjs",
88
"module": "dist/index.js",

src/chain-cache/ChainCache.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ export class ChainCache extends (EventEmitter as new () => TypedEventEmitter<Cac
5656
private _latestTradesByDirectedPair: { [key: string]: TradeData } = {};
5757
private _blocksMetadata: BlockMetadata[] = [];
5858
private _tradingFeePPMByPair: { [key: string]: number } = {};
59-
60-
private _handleCacheMiss:
61-
| ((token0: string, token1: string) => Promise<void>)
62-
| undefined;
6359
//#endregion private members
6460

6561
//#region serialization for persistent caching
@@ -177,20 +173,6 @@ export class ChainCache extends (EventEmitter as new () => TypedEventEmitter<Cac
177173
}
178174
//#endregion serialization for persistent caching
179175

180-
public setCacheMissHandler(
181-
handler: (token0: string, token1: string) => Promise<void>
182-
): void {
183-
this._handleCacheMiss = handler;
184-
}
185-
186-
private async _checkAndHandleCacheMiss(token0: string, token1: string) {
187-
if (!this._handleCacheMiss || this.hasCachedPair(token0, token1)) return;
188-
189-
logger.debug('Cache miss for pair', token0, token1);
190-
await this._handleCacheMiss(token0, token1);
191-
logger.debug('Cache miss for pair', token0, token1, 'resolved');
192-
}
193-
194176
public clear(silent: boolean = false): void {
195177
const pairs = Object.keys(this._strategiesByPair).map(fromPairKey);
196178
this._strategiesByPair = {};
@@ -211,7 +193,6 @@ export class ChainCache extends (EventEmitter as new () => TypedEventEmitter<Cac
211193
token0: string,
212194
token1: string
213195
): Promise<EncodedStrategy[] | undefined> {
214-
await this._checkAndHandleCacheMiss(token0, token1);
215196
const key = toPairKey(token0, token1);
216197
return this._strategiesByPair[key];
217198
}
@@ -257,7 +238,6 @@ export class ChainCache extends (EventEmitter as new () => TypedEventEmitter<Cac
257238
targetToken: string,
258239
keepNonTradable: boolean = false
259240
): Promise<OrdersMap> {
260-
await this._checkAndHandleCacheMiss(sourceToken, targetToken);
261241
const key = toDirectionKey(sourceToken, targetToken);
262242
const orders = this._ordersByDirectedPair[key] || {};
263243

@@ -277,7 +257,6 @@ export class ChainCache extends (EventEmitter as new () => TypedEventEmitter<Cac
277257
token0: string,
278258
token1: string
279259
): Promise<TradeData | undefined> {
280-
await this._checkAndHandleCacheMiss(token0, token1);
281260
const key = toPairKey(token0, token1);
282261
return this._latestTradesByPair[key];
283262
}
@@ -286,7 +265,6 @@ export class ChainCache extends (EventEmitter as new () => TypedEventEmitter<Cac
286265
sourceToken: string,
287266
targetToken: string
288267
): Promise<TradeData | undefined> {
289-
await this._checkAndHandleCacheMiss(sourceToken, targetToken);
290268
const key = toDirectionKey(sourceToken, targetToken);
291269
return this._latestTradesByDirectedPair[key];
292270
}
@@ -303,7 +281,6 @@ export class ChainCache extends (EventEmitter as new () => TypedEventEmitter<Cac
303281
token0: string,
304282
token1: string
305283
): Promise<number | undefined> {
306-
await this._checkAndHandleCacheMiss(token0, token1);
307284
const key = toPairKey(token0, token1);
308285
return this._tradingFeePPMByPair[key];
309286
}

src/chain-cache/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,5 @@ export const initSyncedCache = (
4343
msToWaitBetweenSyncs,
4444
chunkSize
4545
);
46-
cache.setCacheMissHandler(syncer.syncPairData.bind(syncer));
4746
return { cache, startDataSync: syncer.startDataSync.bind(syncer) };
4847
};

src/common/logger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const originalLog = console.log;
1515

1616
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1717
function convertBigNumbersToStrings(obj: any): any {
18+
if (obj === undefined || obj === null) return obj;
1819
if (obj instanceof BigNumber) {
1920
return obj.toString();
2021
}

0 commit comments

Comments
 (0)