Revert "Don't cache empty arrays"

This reverts commit 9ab939456b.
This commit is contained in:
Ajay
2022-07-20 00:23:02 -04:00
parent f2904da653
commit 288f7d45e7
2 changed files with 5 additions and 7 deletions

View File

@@ -262,7 +262,7 @@ async function chooseSegments(videoID: VideoID, service: Service, segments: DBSe
const fetchData = async () => await buildSegmentGroups(segments);
const groups = useCache
? await QueryCacher.get(fetchData, skipSegmentGroupsKey(videoID, service), false)
? await QueryCacher.get(fetchData, skipSegmentGroupsKey(videoID, service))
: await fetchData();
// Filter for only 1 item for POI categories and Full video
@@ -337,7 +337,7 @@ async function buildSegmentGroups(segments: DBSegment[]): Promise<OverlappingSeg
function splitPercentOverlap(groups: OverlappingSegmentGroup[]): OverlappingSegmentGroup[] {
return groups.flatMap((group) => {
const result: OverlappingSegmentGroup[] = [];
for (const segment of group.segments) {
group.segments.forEach((segment) => {
const bestGroup = result.find((group) => {
// At least one segment in the group must have high % overlap or the same action type
// Since POI and Full video segments will always have <= 0 overlap, they will always be in their own groups
@@ -360,7 +360,7 @@ function splitPercentOverlap(groups: OverlappingSegmentGroup[]): OverlappingSegm
} else {
result.push({ segments: [segment], votes: segment.votes, reputation: segment.reputation, locked: segment.locked, required: segment.required });
}
}
});
return result;
});

View File

@@ -4,7 +4,7 @@ import { skipSegmentsHashKey, skipSegmentsKey, reputationKey, ratingHashKey, ski
import { Service, VideoID, VideoIDHash } from "../types/segments.model";
import { Feature, HashedUserID, UserID } from "../types/user.model";
async function get<T>(fetchFromDB: () => Promise<T>, key: string, cacheEmpty = true): Promise<T> {
async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
try {
const reply = await redis.get(key);
if (reply) {
@@ -16,9 +16,7 @@ async function get<T>(fetchFromDB: () => Promise<T>, key: string, cacheEmpty = t
const data = await fetchFromDB();
if (cacheEmpty || data) {
redis.set(key, JSON.stringify(data)).catch((err) => Logger.error(err));
}
return data;
}