aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-03-18 11:17:35 +0100
committerChocobozzz <me@florianbigard.com>2022-03-18 11:21:50 +0100
commit57e4e1c1a95c3a81a967f54ecc2a510d8b0e129c (patch)
treefcf12670d643ec4a3b5eccdfa834227c0417d988 /server/models
parent2e3f7a5a6fbae276d3ba1cb1b08289917ec7604b (diff)
downloadPeerTube-57e4e1c1a95c3a81a967f54ecc2a510d8b0e129c.tar.gz
PeerTube-57e4e1c1a95c3a81a967f54ecc2a510d8b0e129c.tar.zst
PeerTube-57e4e1c1a95c3a81a967f54ecc2a510d8b0e129c.zip
Don't store remote rates of remote videos
In the future we'll stop to expose all available rates to improve users privacy
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/account-video-rate.ts24
-rw-r--r--server/models/video/video.ts16
2 files changed, 16 insertions, 24 deletions
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'
12import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 12import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
13import { CONSTRAINTS_FIELDS, VIDEO_RATE_TYPES } from '../../initializers/constants' 13import { CONSTRAINTS_FIELDS, VIDEO_RATE_TYPES } from '../../initializers/constants'
14import { ActorModel } from '../actor/actor' 14import { ActorModel } from '../actor/actor'
15import { buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils' 15import { getSort, throwIfNotValid } from '../utils'
16import { VideoModel } from '../video/video' 16import { VideoModel } from '../video/video'
17import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from '../video/video-channel' 17import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from '../video/video-channel'
18import { AccountModel } from './account' 18import { AccountModel } from './account'
@@ -249,28 +249,6 @@ export class AccountVideoRateModel extends Model<Partial<AttributesOnly<AccountV
249 ]).then(([ total, data ]) => ({ total, data })) 249 ]).then(([ total, data ]) => ({ total, data }))
250 } 250 }
251 251
252 static cleanOldRatesOf (videoId: number, type: VideoRateType, beforeUpdatedAt: Date) {
253 return AccountVideoRateModel.sequelize.transaction(async t => {
254 const query = {
255 where: {
256 updatedAt: {
257 [Op.lt]: beforeUpdatedAt
258 },
259 videoId,
260 type,
261 accountId: {
262 [Op.notIn]: buildLocalAccountIdsIn()
263 }
264 },
265 transaction: t
266 }
267
268 await AccountVideoRateModel.destroy(query)
269
270 return VideoModel.updateRatesOf(videoId, type, t)
271 })
272 }
273
274 toFormattedJSON (this: MAccountVideoRateFormattable): AccountVideoRate { 252 toFormattedJSON (this: MAccountVideoRateFormattable): AccountVideoRate {
275 return { 253 return {
276 video: this.Video.toFormattedJSON(), 254 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<Partial<AttributesOnly<VideoModel>>> {
1402 }) 1402 })
1403 } 1403 }
1404 1404
1405 static updateRatesOf (videoId: number, type: VideoRateType, t: Transaction) { 1405 static updateRatesOf (videoId: number, type: VideoRateType, count: number, t: Transaction) {
1406 const field = type === 'like'
1407 ? 'likes'
1408 : 'dislikes'
1409
1410 const rawQuery = `UPDATE "video" SET "${field}" = :count WHERE "video"."id" = :videoId`
1411
1412 return AccountVideoRateModel.sequelize.query(rawQuery, {
1413 transaction: t,
1414 replacements: { videoId, rateType: type, count },
1415 type: QueryTypes.UPDATE
1416 })
1417 }
1418
1419 static syncLocalRates (videoId: number, type: VideoRateType, t: Transaction) {
1406 const field = type === 'like' 1420 const field = type === 'like'
1407 ? 'likes' 1421 ? 'likes'
1408 : 'dislikes' 1422 : 'dislikes'