aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-12-21 10:56:57 +0100
committerChocobozzz <me@florianbigard.com>2022-12-21 10:56:57 +0100
commit41027acb0a0c7d59a22f0f56d60928660f576196 (patch)
tree17d930f07437491602347be632b155c60cde69c6 /server
parentd91439648c212f9bca527cbcb05ba2e233b56deb (diff)
parent77f0c0e5dc197729a9255188c210e363b7d90be1 (diff)
downloadPeerTube-41027acb0a0c7d59a22f0f56d60928660f576196.tar.gz
PeerTube-41027acb0a0c7d59a22f0f56d60928660f576196.tar.zst
PeerTube-41027acb0a0c7d59a22f0f56d60928660f576196.zip
Merge branch 'release/5.0.0' into develop
Diffstat (limited to 'server')
-rw-r--r--server/models/video/video-channel.ts37
-rw-r--r--server/tests/api/server/stats.ts3
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<Partial<AttributesOnly<VideoChannel
434 434
435 static async getStats () { 435 static async getStats () {
436 436
437 function getActiveVideoChannels (days: number) { 437 function getLocalVideoChannelStats (days?: number) {
438 const options = { 438 const options = {
439 type: QueryTypes.SELECT as QueryTypes.SELECT, 439 type: QueryTypes.SELECT as QueryTypes.SELECT,
440 raw: true 440 raw: true
441 } 441 }
442 442
443 const videoJoin = days
444 ? `INNER JOIN "video" AS "Videos" ON "VideoChannelModel"."id" = "Videos"."channelId" ` +
445 `AND ("Videos"."publishedAt" > Now() - interval '${days}d')`
446 : ''
447
443 const query = ` 448 const query = `
444SELECT COUNT(DISTINCT("VideoChannelModel"."id")) AS "count" 449 SELECT COUNT(DISTINCT("VideoChannelModel"."id")) AS "count"
445FROM "videoChannel" AS "VideoChannelModel" 450 FROM "videoChannel" AS "VideoChannelModel"
446INNER JOIN "video" AS "Videos" 451 ${videoJoin}
447ON "VideoChannelModel"."id" = "Videos"."channelId" 452 INNER JOIN "account" AS "Account" ON "VideoChannelModel"."accountId" = "Account"."id"
448AND ("Videos"."publishedAt" > Now() - interval '${days}d') 453 INNER JOIN "actor" AS "Account->Actor" ON "Account"."actorId" = "Account->Actor"."id"
449INNER JOIN "account" AS "Account" 454 AND "Account->Actor"."serverId" IS NULL`
450ON "VideoChannelModel"."accountId" = "Account"."id"
451INNER JOIN "actor" AS "Account->Actor"
452ON "Account"."actorId" = "Account->Actor"."id"
453AND "Account->Actor"."serverId" IS NULL
454LEFT OUTER JOIN "server" AS "Account->Actor->Server"
455ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"`
456 455
457 return VideoChannelModel.sequelize.query<{ count: string }>(query, options) 456 return VideoChannelModel.sequelize.query<{ count: string }>(query, options)
458 .then(r => parseInt(r[0].count, 10)) 457 .then(r => parseInt(r[0].count, 10))
459 } 458 }
460 459
461 const totalLocalVideoChannels = await VideoChannelModel.count() 460 const totalLocalVideoChannels = await getLocalVideoChannelStats()
462 const totalLocalDailyActiveVideoChannels = await getActiveVideoChannels(1) 461 const totalLocalDailyActiveVideoChannels = await getLocalVideoChannelStats(1)
463 const totalLocalWeeklyActiveVideoChannels = await getActiveVideoChannels(7) 462 const totalLocalWeeklyActiveVideoChannels = await getLocalVideoChannelStats(7)
464 const totalLocalMonthlyActiveVideoChannels = await getActiveVideoChannels(30) 463 const totalLocalMonthlyActiveVideoChannels = await getLocalVideoChannelStats(30)
465 const totalHalfYearActiveVideoChannels = await getActiveVideoChannels(180) 464 const totalLocalHalfYearActiveVideoChannels = await getLocalVideoChannelStats(180)
466 465
467 return { 466 return {
468 totalLocalVideoChannels, 467 totalLocalVideoChannels,
469 totalLocalDailyActiveVideoChannels, 468 totalLocalDailyActiveVideoChannels,
470 totalLocalWeeklyActiveVideoChannels, 469 totalLocalWeeklyActiveVideoChannels,
471 totalLocalMonthlyActiveVideoChannels, 470 totalLocalMonthlyActiveVideoChannels,
472 totalHalfYearActiveVideoChannels 471 totalLocalHalfYearActiveVideoChannels
473 } 472 }
474 } 473 }
475 474
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 () {
131 { 131 {
132 const data = await server.stats.get() 132 const data = await server.stats.get()
133 133
134 expect(data.totalLocalVideoChannels).to.equal(2)
134 expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) 135 expect(data.totalLocalDailyActiveVideoChannels).to.equal(1)
135 expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) 136 expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1)
136 expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1) 137 expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1)
@@ -146,6 +147,7 @@ describe('Test stats (excluding redundancy)', function () {
146 147
147 const data = await server.stats.get() 148 const data = await server.stats.get()
148 149
150 expect(data.totalLocalVideoChannels).to.equal(3)
149 expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) 151 expect(data.totalLocalDailyActiveVideoChannels).to.equal(1)
150 expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) 152 expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1)
151 expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1) 153 expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1)
@@ -156,6 +158,7 @@ describe('Test stats (excluding redundancy)', function () {
156 158
157 const data = await server.stats.get() 159 const data = await server.stats.get()
158 160
161 expect(data.totalLocalVideoChannels).to.equal(3)
159 expect(data.totalLocalDailyActiveVideoChannels).to.equal(2) 162 expect(data.totalLocalDailyActiveVideoChannels).to.equal(2)
160 expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(2) 163 expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(2)
161 expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(2) 164 expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(2)