From a929f69452181b3e84b1344305171624a0cceb41 Mon Sep 17 00:00:00 2001 From: Ajay Date: Wed, 7 Feb 2024 23:36:45 -0500 Subject: [PATCH] Fix same ip being fetched multiple times from postgres --- src/routes/getSkipSegments.ts | 6 +++--- src/types/segments.model.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/routes/getSkipSegments.ts b/src/routes/getSkipSegments.ts index f2fc200c..89780401 100644 --- a/src/routes/getSkipSegments.ts +++ b/src/routes/getSkipSegments.ts @@ -43,20 +43,20 @@ async function prepareCategorySegments(req: Request, videoID: VideoID, service: try { if (db.highLoad() || privateDB.highLoad()) throw new Error("High load, not handling shadowhide"); - cache.shadowHiddenSegmentIPs[videoID][segment.timeSubmitted] = await promiseOrTimeout(QueryCacher.get(fetchData, shadowHiddenIPKey(videoID, segment.timeSubmitted, service)), 150); + cache.shadowHiddenSegmentIPs[videoID][segment.timeSubmitted] = promiseOrTimeout(QueryCacher.get(fetchData, shadowHiddenIPKey(videoID, segment.timeSubmitted, service)), 150); } catch (e) { // give up on shadowhide for now cache.shadowHiddenSegmentIPs[videoID][segment.timeSubmitted] = null; } } - const ipList = cache.shadowHiddenSegmentIPs[videoID][segment.timeSubmitted]; + const ipList = await cache.shadowHiddenSegmentIPs[videoID][segment.timeSubmitted]; if (ipList?.length > 0 && cache.userHashedIP === undefined) { cache.userHashedIP = await cache.userHashedIPPromise; } //if this isn't their ip, don't send it to them - const shouldShadowHide = cache.shadowHiddenSegmentIPs[videoID][segment.timeSubmitted]?.some( + const shouldShadowHide = ipList?.some( (shadowHiddenSegment) => shadowHiddenSegment.hashedIP === cache.userHashedIP) ?? false; if (shouldShadowHide) useCache = false; diff --git a/src/types/segments.model.ts b/src/types/segments.model.ts index 6f1c3e0c..c58137fe 100644 --- a/src/types/segments.model.ts +++ b/src/types/segments.model.ts @@ -103,7 +103,7 @@ export interface VideoData { } export interface SegmentCache { - shadowHiddenSegmentIPs: SBRecord>, + shadowHiddenSegmentIPs: SBRecord>>, userHashedIP?: HashedIP userHashedIPPromise?: Promise; }