Add redis caching for 404s

This commit is contained in:
Ajay Ramachandran
2021-02-20 21:13:46 -05:00
parent 597dff7ac3
commit 01d318d902
6 changed files with 73 additions and 13 deletions

View File

@@ -11,6 +11,9 @@ import {getIP} from '../utils/getIP';
import {getHash} from '../utils/getHash';
import {config} from '../config';
import { UserID } from '../types/user.model';
import redis from '../utils/redis';
import { skipSegmentsKey } from '../middleware/redisKeys';
import { VideoID } from '../types/segments.model';
const voteTypes = {
normal: 0,
@@ -335,7 +338,8 @@ export async function voteOnSponsorTime(req: Request, res: Response) {
}
//check if the increment amount should be multiplied (downvotes have more power if there have been many views)
const row = db.prepare('get', "SELECT votes, views FROM sponsorTimes WHERE UUID = ?", [UUID]);
const row = db.prepare('get', "SELECT videoID, votes, views FROM sponsorTimes WHERE UUID = ?", [UUID]) as
{videoID: VideoID, votes: number, views: number};
if (voteTypeEnum === voteTypes.normal) {
if ((isVIP || isOwnSubmission) && incrementAmount < 0) {
@@ -383,6 +387,9 @@ export async function voteOnSponsorTime(req: Request, res: Response) {
db.prepare('run', "UPDATE sponsorTimes SET locked = 0 WHERE UUID = ?", [UUID]);
}
// Clear redis cache for this video
redis.delAsync(skipSegmentsKey(row.videoID));
//for each positive vote, see if a hidden submission can be shown again
if (incrementAmount > 0 && voteTypeEnum === voteTypes.normal) {
//find the UUID that submitted the submission that was voted on