From 8fffe21a7bc96d08b229293d66ddba576e609790 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 25 May 2018 16:21:16 +0200 Subject: Refractor and optimize AP collections Only display urls in general object, and paginate video comments, shares, likes and dislikes --- server/models/account/account-video-rate.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'server/models/account') diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts index e969e4a43..508ab814f 100644 --- a/server/models/account/account-video-rate.ts +++ b/server/models/account/account-video-rate.ts @@ -6,6 +6,7 @@ import { VideoRateType } from '../../../shared/models/videos' import { VIDEO_RATE_TYPES } from '../../initializers' import { VideoModel } from '../video/video' import { AccountModel } from './account' +import { ActorModel } from '../activitypub/actor' /* Account rates per video. @@ -66,4 +67,32 @@ export class AccountVideoRateModel extends Model { return AccountVideoRateModel.findOne(options) } + + static listAndCountAccountUrlsByVideoId (rateType: VideoRateType, videoId: number, start: number, count: number, t?: Transaction) { + const query = { + start, + count, + where: { + videoId, + type: rateType + }, + transaction: t, + include: [ + { + attributes: [ 'actorId' ], + model: AccountModel.unscoped(), + required: true, + include: [ + { + attributes: [ 'url' ], + model: ActorModel.unscoped(), + required: true + } + ] + } + ] + } + + return AccountVideoRateModel.findAndCountAll(query) + } } -- cgit v1.2.3