From 21c3e8ca8eecbb8479aaee30d45a4d7e6c88babb Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Sun, 10 Dec 2023 15:20:01 -0800 Subject: [PATCH] cache consistent stringify --- src/index.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index c4031da..02db2bd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -815,7 +815,7 @@ const main = async () => { if (l2Formatted) { cacheHitCounter.add(1); res.writeHead(200); - res.end(JSON.stringify(l2Formatted)); + res.end(l2Formatted); return; } } @@ -960,11 +960,11 @@ const main = async () => { `last_update_orderbook_perp_${normedMarketIndex}_depth_100` ); } - if ( - redisL2 && - slotSource.getSlot() - parseInt(JSON.parse(redisL2).slot) < 10 - ) - l2Formatted = redisL2; + if (redisL2) { + const parsedRedisL2 = JSON.parse(redisL2); + if (slotSource.getSlot() - parseInt(parsedRedisL2.slot) < 10) + l2Formatted = parsedRedisL2; + } } else if ( marketType === 'spot' && normedParam['includePhoenix'].toLowerCase() === 'true' && @@ -985,11 +985,11 @@ const main = async () => { `last_update_orderbook_spot_${normedMarketIndex}_depth_100` ); } - if ( - redisL2 && - slotSource.getSlot() - parseInt(JSON.parse(redisL2).slot) < 10 - ) - l2Formatted = redisL2; + if (redisL2) { + const parsedRedisL2 = JSON.parse(redisL2); + if (slotSource.getSlot() - parseInt(parsedRedisL2.slot) < 10) + l2Formatted = parsedRedisL2; + } } if (l2Formatted) {