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/account/account-video-rate.ts | 24 +----------------------- server/models/video/video.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 24 deletions(-) (limited to 'server/models') diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts index 7303651eb..5c7d9cfc0 100644 --- a/server/models/account/account-video-rate.ts +++ b/server/models/account/account-video-rate.ts @@ -12,7 +12,7 @@ import { AttributesOnly } from '@shared/typescript-utils' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { CONSTRAINTS_FIELDS, VIDEO_RATE_TYPES } from '../../initializers/constants' import { ActorModel } from '../actor/actor' -import { buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils' +import { getSort, throwIfNotValid } from '../utils' import { VideoModel } from '../video/video' import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from '../video/video-channel' import { AccountModel } from './account' @@ -249,28 +249,6 @@ export class AccountVideoRateModel extends Model ({ total, data })) } - static cleanOldRatesOf (videoId: number, type: VideoRateType, beforeUpdatedAt: Date) { - return AccountVideoRateModel.sequelize.transaction(async t => { - const query = { - where: { - updatedAt: { - [Op.lt]: beforeUpdatedAt - }, - videoId, - type, - accountId: { - [Op.notIn]: buildLocalAccountIdsIn() - } - }, - transaction: t - } - - await AccountVideoRateModel.destroy(query) - - return VideoModel.updateRatesOf(videoId, type, t) - }) - } - toFormattedJSON (this: MAccountVideoRateFormattable): AccountVideoRate { return { video: this.Video.toFormattedJSON(), 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