diff --git a/src/routes/shadowBanUser.ts b/src/routes/shadowBanUser.ts index 17b9798..3f5e541 100644 --- a/src/routes/shadowBanUser.ts +++ b/src/routes/shadowBanUser.ts @@ -2,6 +2,9 @@ import {db, privateDB} from '../databases/databases'; import {getHash} from '../utils/getHash'; import {Request, Response} from 'express'; import { config } from '../config'; +import { Category, Service, VideoID, VideoIDHash } from '../types/segments.model'; +import { UserID } from '../types/user.model'; +import { QueryCacher } from '../utils/queryCacher'; export async function shadowBanUser(req: Request, res: Response) { const userID = req.query.userID as string; @@ -49,6 +52,11 @@ export async function shadowBanUser(req: Request, res: Response) { await db.prepare('run', `UPDATE "sponsorTimes" SET "shadowHidden" = 1 WHERE "userID" = ? AND "category" in (${categories.map((c) => `'${c}'`).join(",")}) AND NOT EXISTS ( SELECT "videoID", "category" FROM "lockCategories" WHERE "sponsorTimes"."videoID" = "lockCategories"."videoID" AND "sponsorTimes"."category" = "lockCategories"."category")`, [userID]); + // clear cache for all old videos + (await db.prepare('all', `SELECT "videoID", "hashedVideoID", "service", "votes", "views" FROM "sponsorTimes" WHERE "userID" = ?`, [userID])) + .map((videoInfo: {category: Category, videoID: VideoID, hashedVideoID: VideoIDHash, service: Service, userID: UserID}) => { + QueryCacher.clearVideoCache(videoInfo); + }); } } else if (!enabled && row.userCount > 0) { //remove them from the shadow ban list @@ -64,7 +72,13 @@ export async function shadowBanUser(req: Request, res: Response) { await Promise.all(allSegments.filter((item: {uuid: string}) => { return segmentsToIgnore.indexOf(item) === -1; - }).map((UUID: string) => { + }).map(async (UUID: string) => { + // collect list for unshadowbanning + (await db.prepare('all', `SELECT "videoID", "hashedVideoID", "service", "votes", "views", "userID" FROM "sponsorTimes" WHERE "UUID" = ? AND "shadowHidden" = 1 AND "category" in (${categories.map((c) => `'${c}'`).join(",")})`, [UUID])) + .map((videoInfo: {category: Category, videoID: VideoID, hashedVideoID: VideoIDHash, service: Service, userID: UserID}) => { + QueryCacher.clearVideoCache(videoInfo); + }) + // unhide return db.prepare('run', `UPDATE "sponsorTimes" SET "shadowHidden" = 0 WHERE "UUID" = ? AND "category" in (${categories.map((c) => `'${c}'`).join(",")})`, [UUID]); })); }