Clear query cache for branding

This commit is contained in:
Ajay 2023-03-29 00:32:29 -04:00
parent 19ebca86c9
commit 4696ce8d01
3 changed files with 16 additions and 1 deletions

View file

@ -11,6 +11,7 @@ import { getService } from "../utils/getService";
import { isUserVIP } from "../utils/isUserVIP"; import { isUserVIP } from "../utils/isUserVIP";
import { Logger } from "../utils/logger"; import { Logger } from "../utils/logger";
import crypto from "crypto"; import crypto from "crypto";
import { QueryCacher } from "../utils/queryCacher";
enum BrandingType { enum BrandingType {
Title, Title,
@ -96,6 +97,7 @@ export async function postBranding(req: Request, res: Response) {
} }
})()]); })()]);
QueryCacher.clearBrandingCache({ videoID, hashedVideoID, service });
res.status(200).send("OK"); res.status(200).send("OK");
} catch (e) { } catch (e) {
Logger.error(e as string); Logger.error(e as string);

View file

@ -44,6 +44,11 @@ export async function postClearCache(req: Request, res: Response): Promise<Respo
hashedVideoID, hashedVideoID,
service service
}); });
QueryCacher.clearBrandingCache({
videoID,
hashedVideoID,
service
});
return res.status(200).json({ return res.status(200).json({
message: `Cache cleared on video ${videoID}` message: `Cache cleared on video ${videoID}`
}); });

View file

@ -1,6 +1,6 @@
import redis from "../utils/redis"; import redis from "../utils/redis";
import { Logger } from "../utils/logger"; import { Logger } from "../utils/logger";
import { skipSegmentsHashKey, skipSegmentsKey, reputationKey, ratingHashKey, skipSegmentGroupsKey, userFeatureKey, videoLabelsKey, videoLabelsHashKey } from "./redisKeys"; import { skipSegmentsHashKey, skipSegmentsKey, reputationKey, ratingHashKey, skipSegmentGroupsKey, userFeatureKey, videoLabelsKey, videoLabelsHashKey, brandingHashKey, brandingKey } from "./redisKeys";
import { Service, VideoID, VideoIDHash } from "../types/segments.model"; import { Service, VideoID, VideoIDHash } from "../types/segments.model";
import { Feature, HashedUserID, UserID } from "../types/user.model"; import { Feature, HashedUserID, UserID } from "../types/user.model";
import { config } from "../config"; import { config } from "../config";
@ -87,6 +87,13 @@ function clearSegmentCache(videoInfo: { videoID: VideoID; hashedVideoID: VideoID
} }
} }
function clearBrandingCache(videoInfo: { videoID: VideoID; hashedVideoID: VideoIDHash; service: Service; }): void {
if (videoInfo) {
redis.del(brandingHashKey(videoInfo.hashedVideoID, videoInfo.service)).catch((err) => Logger.error(err));
redis.del(brandingKey(videoInfo.videoID, videoInfo.service)).catch((err) => Logger.error(err));
}
}
async function getKeyLastModified(key: string): Promise<Date> { async function getKeyLastModified(key: string): Promise<Date> {
if (!config.redis?.enabled) return Promise.reject("ETag - Redis not enabled"); if (!config.redis?.enabled) return Promise.reject("ETag - Redis not enabled");
return await redis.ttl(key) return await redis.ttl(key)
@ -112,6 +119,7 @@ export const QueryCacher = {
get, get,
getAndSplit, getAndSplit,
clearSegmentCache, clearSegmentCache,
clearBrandingCache,
getKeyLastModified, getKeyLastModified,
clearRatingCache, clearRatingCache,
clearFeatureCache, clearFeatureCache,