From c6f8ca4d6596572de981162983bd02eb2613791d Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Tue, 31 May 2022 16:01:11 +0200 Subject: Added "total views" in the my channels list (#5007) * Added "total views" in the my channels list Implements https://github.com/Chocobozzz/PeerTube/issues/4331 * Fix lint * applied suggested change * updated openAPI spec for the use "withStats" when getting video channels * applied code change * removed GROUP BY in query * Fixed test --- server/models/video/video-channel.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'server/models') diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index d6dd1b8bb..91dafbcf1 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -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' ] ] } @@ -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, -- cgit v1.2.3