aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-12-21 10:46:55 +0100
committerChocobozzz <me@florianbigard.com>2022-12-21 10:46:58 +0100
commitdfa4944f3401b5c1225e3235a016510c9f5a7c8a (patch)
tree571cea068b2f8342de27ed801845fcf99bd53331 /server/models/video
parent57e11a20f12c69927e5739ecf541ed340934ff90 (diff)
downloadPeerTube-dfa4944f3401b5c1225e3235a016510c9f5a7c8a.tar.gz
PeerTube-dfa4944f3401b5c1225e3235a016510c9f5a7c8a.tar.zst
PeerTube-dfa4944f3401b5c1225e3235a016510c9f5a7c8a.zip
Fix local channel stats
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-channel.ts37
1 files changed, 18 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