X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-channel.ts;h=91dafbcf1d996d6b6973d0495bdc1486c9b1a0a3;hb=a2fb5fb8b1007e3ce82e707917f5d9a37374e99b;hp=410fd6d3f777c4e15c2bb0f509eb2012eb0210de;hpb=28dca0a2211524bbf3ad17666c607eb6325763b8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 410fd6d3f..91dafbcf1 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -143,28 +143,28 @@ export type SummaryOptions = { }) } - const channelInclude: Includeable[] = [] - const accountInclude: Includeable[] = [] + const channelActorInclude: Includeable[] = [] + const accountActorInclude: Includeable[] = [] if (options.forCount !== true) { - accountInclude.push({ + accountActorInclude.push({ model: ServerModel, required: false }) - accountInclude.push({ + accountActorInclude.push({ model: ActorImageModel, as: 'Avatars', required: false }) - channelInclude.push({ + channelActorInclude.push({ model: ActorImageModel, as: 'Avatars', required: false }) - channelInclude.push({ + channelActorInclude.push({ model: ActorImageModel, as: 'Banners', required: false @@ -172,7 +172,7 @@ export type SummaryOptions = { } if (options.forCount !== true || serverRequired) { - channelInclude.push({ + channelActorInclude.push({ model: ServerModel, duplicating: false, required: serverRequired, @@ -190,7 +190,7 @@ export type SummaryOptions = { where: { [Op.and]: whereActorAnd }, - include: channelInclude + include: channelActorInclude }, { model: AccountModel.unscoped(), @@ -202,7 +202,7 @@ export type SummaryOptions = { }, model: ActorModel.unscoped(), required: true, - include: accountInclude + include: accountActorInclude } ] } @@ -311,6 +311,16 @@ export type SummaryOptions = { ')' ), 'viewsPerDay' + ], + [ + literal( + '(' + + 'SELECT COALESCE(SUM("video".views), 0) AS totalViews ' + + 'FROM "video" ' + + 'WHERE "video"."channelId" = "VideoChannelModel"."id"' + + ')' + ), + 'totalViews' ] ] } @@ -419,7 +429,7 @@ export class VideoChannelModel extends ModelActor"."serverId" = "Account->Actor->Server"."id"` } } - const scopes: string | ScopeOptions | (string | ScopeOptions)[] = [ ScopeNames.WITH_ACTOR_BANNER ] + const findScopes: string | ScopeOptions | (string | ScopeOptions)[] = [ ScopeNames.WITH_ACTOR_BANNER ] if (options.withStats === true) { - scopes.push({ + findScopes.push({ method: [ ScopeNames.WITH_STATS, { daysPrior: 30 } as AvailableWithStatsOptions ] }) } return Promise.all([ - VideoChannelModel.scope(scopes).count(getQuery(true)), - VideoChannelModel.scope(scopes).findAll(getQuery(false)) + VideoChannelModel.unscoped().count(getQuery(true)), + VideoChannelModel.scope(findScopes).findAll(getQuery(false)) ]).then(([ total, data ]) => ({ total, data })) } @@ -766,6 +776,8 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` }) } + const totalViews = this.get('totalViews') as number + const actor = this.Actor.toFormattedJSON() const videoChannel = { id: this.id, @@ -779,6 +791,7 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` videosCount, viewsPerDay, + totalViews, avatars: actor.avatars,