aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts20
1 files changed, 19 insertions, 1 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 8894843e0..b4c7da655 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -34,7 +34,7 @@ import { ModelCache } from '@server/models/model-cache'
34import { VideoFile } from '@shared/models/videos/video-file.model' 34import { VideoFile } from '@shared/models/videos/video-file.model'
35import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' 35import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared'
36import { VideoObject } from '../../../shared/models/activitypub/objects' 36import { VideoObject } from '../../../shared/models/activitypub/objects'
37import { Video, VideoDetails } from '../../../shared/models/videos' 37import { Video, VideoDetails, VideoRateType } from '../../../shared/models/videos'
38import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' 38import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
39import { VideoFilter } from '../../../shared/models/videos/video-query.type' 39import { VideoFilter } from '../../../shared/models/videos/video-query.type'
40import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' 40import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
@@ -1509,6 +1509,24 @@ export class VideoModel extends Model {
1509 }) 1509 })
1510 } 1510 }
1511 1511
1512 static updateRatesOf (videoId: number, type: VideoRateType, t: Transaction) {
1513 const field = type === 'like'
1514 ? 'likes'
1515 : 'dislikes'
1516
1517 const rawQuery = `UPDATE "video" SET "${field}" = ` +
1518 '(' +
1519 'SELECT COUNT(id) FROM "accountVideoRate" WHERE "accountVideoRate"."videoId" = "video"."id" AND type = :rateType' +
1520 ') ' +
1521 'WHERE "video"."id" = :videoId'
1522
1523 return AccountVideoRateModel.sequelize.query(rawQuery, {
1524 transaction: t,
1525 replacements: { videoId, rateType: type },
1526 type: QueryTypes.UPDATE
1527 })
1528 }
1529
1512 static checkVideoHasInstanceFollow (videoId: number, followerActorId: number) { 1530 static checkVideoHasInstanceFollow (videoId: number, followerActorId: number) {
1513 // Instances only share videos 1531 // Instances only share videos
1514 const query = 'SELECT 1 FROM "videoShare" ' + 1532 const query = 'SELECT 1 FROM "videoShare" ' +