Skip to content

Commit

Permalink
Fix same ip being fetched multiple times from postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Feb 8, 2024
1 parent 8574ec3 commit a929f69
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/routes/getSkipSegments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/types/segments.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export interface VideoData {
}

export interface SegmentCache {
shadowHiddenSegmentIPs: SBRecord<VideoID, SBRecord<string, {hashedIP: HashedIP}[]>>,
shadowHiddenSegmentIPs: SBRecord<VideoID, SBRecord<string, Promise<{hashedIP: HashedIP}[] | null>>>,
userHashedIP?: HashedIP
userHashedIPPromise?: Promise<HashedIP>;
}
Expand Down

0 comments on commit a929f69

Please sign in to comment.