From dfa4944f3401b5c1225e3235a016510c9f5a7c8a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 21 Dec 2022 10:46:55 +0100 Subject: [PATCH 1/2] Fix local channel stats --- server/models/video/video-channel.ts | 37 ++++++++++++++-------------- server/tests/api/server/stats.ts | 3 +++ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 9e461b6ca..132c8f021 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -434,42 +434,41 @@ export class VideoChannelModel extends Model Now() - interval '${days}d')` + : '' + const query = ` -SELECT COUNT(DISTINCT("VideoChannelModel"."id")) AS "count" -FROM "videoChannel" AS "VideoChannelModel" -INNER JOIN "video" AS "Videos" -ON "VideoChannelModel"."id" = "Videos"."channelId" -AND ("Videos"."publishedAt" > Now() - interval '${days}d') -INNER JOIN "account" AS "Account" -ON "VideoChannelModel"."accountId" = "Account"."id" -INNER JOIN "actor" AS "Account->Actor" -ON "Account"."actorId" = "Account->Actor"."id" -AND "Account->Actor"."serverId" IS NULL -LEFT OUTER JOIN "server" AS "Account->Actor->Server" -ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` + SELECT COUNT(DISTINCT("VideoChannelModel"."id")) AS "count" + FROM "videoChannel" AS "VideoChannelModel" + ${videoJoin} + INNER JOIN "account" AS "Account" ON "VideoChannelModel"."accountId" = "Account"."id" + INNER JOIN "actor" AS "Account->Actor" ON "Account"."actorId" = "Account->Actor"."id" + AND "Account->Actor"."serverId" IS NULL` return VideoChannelModel.sequelize.query<{ count: string }>(query, options) .then(r => parseInt(r[0].count, 10)) } - const totalLocalVideoChannels = await VideoChannelModel.count() - const totalLocalDailyActiveVideoChannels = await getActiveVideoChannels(1) - const totalLocalWeeklyActiveVideoChannels = await getActiveVideoChannels(7) - const totalLocalMonthlyActiveVideoChannels = await getActiveVideoChannels(30) - const totalHalfYearActiveVideoChannels = await getActiveVideoChannels(180) + const totalLocalVideoChannels = await getLocalVideoChannelStats() + const totalLocalDailyActiveVideoChannels = await getLocalVideoChannelStats(1) + const totalLocalWeeklyActiveVideoChannels = await getLocalVideoChannelStats(7) + const totalLocalMonthlyActiveVideoChannels = await getLocalVideoChannelStats(30) + const totalLocalHalfYearActiveVideoChannels = await getLocalVideoChannelStats(180) return { totalLocalVideoChannels, totalLocalDailyActiveVideoChannels, totalLocalWeeklyActiveVideoChannels, totalLocalMonthlyActiveVideoChannels, - totalHalfYearActiveVideoChannels + totalLocalHalfYearActiveVideoChannels } } diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index 83b0e73d6..942cbeaa4 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -131,6 +131,7 @@ describe('Test stats (excluding redundancy)', function () { { const data = await server.stats.get() + expect(data.totalLocalVideoChannels).to.equal(2) expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1) @@ -146,6 +147,7 @@ describe('Test stats (excluding redundancy)', function () { const data = await server.stats.get() + expect(data.totalLocalVideoChannels).to.equal(3) expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1) @@ -156,6 +158,7 @@ describe('Test stats (excluding redundancy)', function () { const data = await server.stats.get() + expect(data.totalLocalVideoChannels).to.equal(3) expect(data.totalLocalDailyActiveVideoChannels).to.equal(2) expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(2) expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(2) From 77f0c0e5dc197729a9255188c210e363b7d90be1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 21 Dec 2022 10:52:33 +0100 Subject: [PATCH 2/2] Display video actions in homepage --- .../peertube-custom-tags/video-miniature-markup.component.html | 2 +- .../peertube-custom-tags/videos-list-markup.component.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/app/shared/shared-custom-markup/peertube-custom-tags/video-miniature-markup.component.html b/client/src/app/shared/shared-custom-markup/peertube-custom-tags/video-miniature-markup.component.html index 9b4930b6d..e383e0c75 100644 --- a/client/src/app/shared/shared-custom-markup/peertube-custom-tags/video-miniature-markup.component.html +++ b/client/src/app/shared/shared-custom-markup/peertube-custom-tags/video-miniature-markup.component.html @@ -1,6 +1,6 @@ diff --git a/client/src/app/shared/shared-custom-markup/peertube-custom-tags/videos-list-markup.component.html b/client/src/app/shared/shared-custom-markup/peertube-custom-tags/videos-list-markup.component.html index 15ef9d418..868bda387 100644 --- a/client/src/app/shared/shared-custom-markup/peertube-custom-tags/videos-list-markup.component.html +++ b/client/src/app/shared/shared-custom-markup/peertube-custom-tags/videos-list-markup.component.html @@ -4,7 +4,7 @@