mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-16 08:26:59 +03:00
Clear reputation cache
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import redis from "../utils/redis";
|
||||
import { Logger } from "../utils/logger";
|
||||
import { skipSegmentsHashKey, skipSegmentsKey } from "./redisKeys";
|
||||
import { skipSegmentsHashKey, skipSegmentsKey, reputationKey } from "./redisKeys";
|
||||
import { Service, VideoID, VideoIDHash } from "../types/segments.model";
|
||||
import { UserID } from "../types/user.model";
|
||||
|
||||
async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
|
||||
const {err, reply} = await redis.getAsync(key);
|
||||
@@ -21,10 +22,11 @@ async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
|
||||
return data;
|
||||
}
|
||||
|
||||
function clearVideoCache(videoInfo: { videoID: VideoID; hashedVideoID: VideoIDHash; service: Service; }) {
|
||||
function clearVideoCache(videoInfo: { videoID: VideoID; hashedVideoID: VideoIDHash; service: Service; userID: UserID; }) {
|
||||
if (videoInfo) {
|
||||
redis.delAsync(skipSegmentsKey(videoInfo.videoID, videoInfo.service));
|
||||
redis.delAsync(skipSegmentsHashKey(videoInfo.hashedVideoID, videoInfo.service));
|
||||
redis.delAsync(reputationKey(videoInfo.userID));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,6 @@ export function skipSegmentsHashKey(hashedVideoIDPrefix: VideoIDHash, service: S
|
||||
return "segments." + service + "." + hashedVideoIDPrefix;
|
||||
}
|
||||
|
||||
export function userKey(userID: UserID): string {
|
||||
return "user." + userID;
|
||||
export function reputationKey(userID: UserID): string {
|
||||
return "reputation.user." + userID;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { db } from "../databases/databases";
|
||||
import { UserID } from "../types/user.model";
|
||||
import { QueryCacher } from "./queryCacher";
|
||||
import { userKey } from "./redisKeys";
|
||||
import { reputationKey } from "./redisKeys";
|
||||
|
||||
interface ReputationDBResult {
|
||||
totalSubmissions: number,
|
||||
@@ -19,7 +19,7 @@ export async function getReputation(userID: UserID) {
|
||||
SUM(CASE WHEN "timeSubmitted" < ? AND "votes" > 0 THEN 1 ELSE 0 END) AS "oldUpvotedSubmissions"
|
||||
FROM "sponsorTimes" WHERE "userID" = ?`, [pastDate, userID]) as Promise<ReputationDBResult>;
|
||||
|
||||
const result = await QueryCacher.get(fetchFromDB, userKey(userID));
|
||||
const result = await QueryCacher.get(fetchFromDB, reputationKey(userID));
|
||||
|
||||
// Grace period
|
||||
if (result.totalSubmissions < 5) {
|
||||
|
||||
Reference in New Issue
Block a user