From f0ba9da8af9abc24fdae0b6fe65b83326d904e44 Mon Sep 17 00:00:00 2001 From: enes Date: Mon, 9 Sep 2024 14:16:58 +0200 Subject: [PATCH] fix: outdated cache checks --- src/utils/relays.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/relays.ts b/src/utils/relays.ts index 5b79f3d..bfef7aa 100644 --- a/src/utils/relays.ts +++ b/src/utils/relays.ts @@ -6,6 +6,7 @@ import { localCache } from '../services' import { RelayMap, RelaySet } from '../types' import { DEFAULT_LOOK_UP_RELAY_LIST, + ONE_DAY_IN_MS, ONE_WEEK_IN_MS, SIGIT_RELAY } from './const' @@ -56,7 +57,7 @@ const findRelayListInCache = async (hexKey: string): Promise => { // Check if the cached event is not older than one week if ( cachedRelayListMetadataEvent && - isOlderThanOneWeek(cachedRelayListMetadataEvent.cachedAt) + !isOlderThanOneWeek(cachedRelayListMetadataEvent.cachedAt) ) { return cachedRelayListMetadataEvent.event } @@ -88,11 +89,11 @@ const getDefaultRelayMap = (): RelayMap => ({ }) const isOlderThanOneWeek = (cachedAt: number) => { - return Date.now() - cachedAt < ONE_WEEK_IN_MS + return Date.now() - cachedAt > ONE_WEEK_IN_MS } const isOlderThanOneDay = (cachedAt: number) => { - return Date.now() - cachedAt < ONE_WEEK_IN_MS + return Date.now() - cachedAt > ONE_DAY_IN_MS } const isRelayTag = (tag: string[]): boolean => tag[0] === 'r' -- 2.34.1