From 57e4e1c1a95c3a81a967f54ecc2a510d8b0e129c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 18 Mar 2022 11:17:35 +0100 Subject: Don't store remote rates of remote videos In the future we'll stop to expose all available rates to improve users privacy --- server/models/video/video.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'server/models/video') diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 4147b3d62..8bad2a01e 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -1402,7 +1402,21 @@ export class VideoModel extends Model>> { }) } - static updateRatesOf (videoId: number, type: VideoRateType, t: Transaction) { + static updateRatesOf (videoId: number, type: VideoRateType, count: number, t: Transaction) { + const field = type === 'like' + ? 'likes' + : 'dislikes' + + const rawQuery = `UPDATE "video" SET "${field}" = :count WHERE "video"."id" = :videoId` + + return AccountVideoRateModel.sequelize.query(rawQuery, { + transaction: t, + replacements: { videoId, rateType: type, count }, + type: QueryTypes.UPDATE + }) + } + + static syncLocalRates (videoId: number, type: VideoRateType, t: Transaction) { const field = type === 'like' ? 'likes' : 'dislikes' -- cgit v1.2.3