Skip to content

Commit

Permalink
Add cid to choose segments
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Nov 3, 2024
1 parent a01fccf commit 27ab1ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 8 additions & 6 deletions src/routes/getSkipSegments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async function prepareCategorySegments(

const filteredSegments = segments.filter((_, index) => shouldFilter[index]);

return (await chooseSegments(videoID, service, filteredSegments, useCache)).map(
return (await chooseSegments(videoID, cid, service, filteredSegments, useCache)).map(
(chosenSegment) =>
({
cid: chosenSegment.cid,
Expand Down Expand Up @@ -221,24 +221,25 @@ async function getSegmentsByHash(
const segmentPerVideoID: SegmentPerVideoID = (await getSegmentsFromDBByHash(hashedVideoIDPrefix, service))
.filter((segment) => !cid || segment.cid == cid)
.reduce((acc: SegmentPerVideoID, segment: DBSegment) => {
acc[segment.videoID] = acc[segment.videoID] || {
acc[`${segment.videoID},${segment.cid}`] = acc[`${segment.videoID},${segment.cid}`] || {
segments: [],
};
if (filterRequiredSegments(segment.UUID, requiredSegments)) segment.required = true;

acc[segment.videoID].segments ??= [];
acc[segment.videoID].segments.push(segment);
acc[`${segment.videoID},${segment.cid}`].segments ??= [];
acc[`${segment.videoID},${segment.cid}`].segments.push(segment);

return acc;
}, {});

await Promise.all(
Object.entries(segmentPerVideoID).map(async ([videoID, videoData]) => {
Object.entries(segmentPerVideoID).map(async ([videoIdCid, videoData]) => {
const data: VideoData = {
segments: [],
};

const canUseCache = requiredSegments.length === 0;
const [videoID, cid] = videoIdCid.split(",");
data.segments = (
await prepareCategorySegments(
req,
Expand Down Expand Up @@ -343,6 +344,7 @@ function getBestChoice<T extends VotableObject>(

async function chooseSegments(
videoID: VideoID,
cid: string,
service: Service,
segments: DBSegment[],
useCache: boolean
Expand All @@ -351,7 +353,7 @@ async function chooseSegments(

const groups =
useCache && config.useCacheForSegmentGroups
? await QueryCacher.get(fetchData, skipSegmentGroupsKey(videoID, service))
? await QueryCacher.get(fetchData, skipSegmentGroupsKey(videoID, cid, service))
: await fetchData();

// Filter for only 1 item for POI categories and Full video
Expand Down
14 changes: 6 additions & 8 deletions src/utils/redisKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { RedisCommandArgument } from "@redis/client/dist/lib/commands";
export const skipSegmentsKey = (videoID: VideoID, service: Service): string =>
`segments.v5.${service}.videoID.${videoID}`;

export const skipSegmentGroupsKey = (videoID: VideoID, service: Service): string =>
`segments.groups.v4.${service}.videoID.${videoID}`;
export const skipSegmentGroupsKey = (videoID: VideoID, cid: string, service: Service): string =>
`segments.groups.v4.${service}.videoID.${videoID}.${cid}`;

export function skipSegmentsHashKey(hashedVideoIDPrefix: VideoIDHash, service: Service): string {
hashedVideoIDPrefix = hashedVideoIDPrefix.substring(0, 4) as VideoIDHash;
Expand Down Expand Up @@ -36,11 +36,9 @@ export function shaHashKey(singleIter: HashedValue): string {
return `sha.hash.${singleIter}`;
}

export const tempVIPKey = (userID: HashedUserID): string =>
`vip.temp.${userID}`;
export const tempVIPKey = (userID: HashedUserID): string => `vip.temp.${userID}`;

export const videoLabelsKey = (videoID: VideoID, service: Service): string =>
`labels.v1.${service}.videoID.${videoID}`;
export const videoLabelsKey = (videoID: VideoID, service: Service): string => `labels.v1.${service}.videoID.${videoID}`;

export function videoLabelsHashKey(hashedVideoIDPrefix: VideoIDHash, service: Service): string {
hashedVideoIDPrefix = hashedVideoIDPrefix.substring(0, 3) as VideoIDHash;
Expand All @@ -49,7 +47,7 @@ export function videoLabelsHashKey(hashedVideoIDPrefix: VideoIDHash, service: Se
return `labels.v1.${service}.${hashedVideoIDPrefix}`;
}

export function userFeatureKey (userID: HashedUserID, feature: Feature): string {
export function userFeatureKey(userID: HashedUserID, feature: Feature): string {
return `user.v1.${userID}.feature.${feature}`;
}

Expand Down Expand Up @@ -79,4 +77,4 @@ export function portVideoUserCountKey() {

export function videoDetailCacheKey(videoID: string) {
return `video.detail.v1.videoID.${videoID}`;
}
}

0 comments on commit 27ab1ce

Please sign in to comment.