Fix local channel stats
This commit is contained in:
parent
57e11a20f1
commit
dfa4944f34
|
@ -434,42 +434,41 @@ export class VideoChannelModel extends Model<Partial<AttributesOnly<VideoChannel
|
||||||
|
|
||||||
static async getStats () {
|
static async getStats () {
|
||||||
|
|
||||||
function getActiveVideoChannels (days: number) {
|
function getLocalVideoChannelStats (days?: number) {
|
||||||
const options = {
|
const options = {
|
||||||
type: QueryTypes.SELECT as QueryTypes.SELECT,
|
type: QueryTypes.SELECT as QueryTypes.SELECT,
|
||||||
raw: true
|
raw: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const videoJoin = days
|
||||||
|
? `INNER JOIN "video" AS "Videos" ON "VideoChannelModel"."id" = "Videos"."channelId" ` +
|
||||||
|
`AND ("Videos"."publishedAt" > Now() - interval '${days}d')`
|
||||||
|
: ''
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
SELECT COUNT(DISTINCT("VideoChannelModel"."id")) AS "count"
|
SELECT COUNT(DISTINCT("VideoChannelModel"."id")) AS "count"
|
||||||
FROM "videoChannel" AS "VideoChannelModel"
|
FROM "videoChannel" AS "VideoChannelModel"
|
||||||
INNER JOIN "video" AS "Videos"
|
${videoJoin}
|
||||||
ON "VideoChannelModel"."id" = "Videos"."channelId"
|
INNER JOIN "account" AS "Account" ON "VideoChannelModel"."accountId" = "Account"."id"
|
||||||
AND ("Videos"."publishedAt" > Now() - interval '${days}d')
|
INNER JOIN "actor" AS "Account->Actor" ON "Account"."actorId" = "Account->Actor"."id"
|
||||||
INNER JOIN "account" AS "Account"
|
AND "Account->Actor"."serverId" IS NULL`
|
||||||
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"`
|
|
||||||
|
|
||||||
return VideoChannelModel.sequelize.query<{ count: string }>(query, options)
|
return VideoChannelModel.sequelize.query<{ count: string }>(query, options)
|
||||||
.then(r => parseInt(r[0].count, 10))
|
.then(r => parseInt(r[0].count, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalLocalVideoChannels = await VideoChannelModel.count()
|
const totalLocalVideoChannels = await getLocalVideoChannelStats()
|
||||||
const totalLocalDailyActiveVideoChannels = await getActiveVideoChannels(1)
|
const totalLocalDailyActiveVideoChannels = await getLocalVideoChannelStats(1)
|
||||||
const totalLocalWeeklyActiveVideoChannels = await getActiveVideoChannels(7)
|
const totalLocalWeeklyActiveVideoChannels = await getLocalVideoChannelStats(7)
|
||||||
const totalLocalMonthlyActiveVideoChannels = await getActiveVideoChannels(30)
|
const totalLocalMonthlyActiveVideoChannels = await getLocalVideoChannelStats(30)
|
||||||
const totalHalfYearActiveVideoChannels = await getActiveVideoChannels(180)
|
const totalLocalHalfYearActiveVideoChannels = await getLocalVideoChannelStats(180)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
totalLocalVideoChannels,
|
totalLocalVideoChannels,
|
||||||
totalLocalDailyActiveVideoChannels,
|
totalLocalDailyActiveVideoChannels,
|
||||||
totalLocalWeeklyActiveVideoChannels,
|
totalLocalWeeklyActiveVideoChannels,
|
||||||
totalLocalMonthlyActiveVideoChannels,
|
totalLocalMonthlyActiveVideoChannels,
|
||||||
totalHalfYearActiveVideoChannels
|
totalLocalHalfYearActiveVideoChannels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,7 @@ describe('Test stats (excluding redundancy)', function () {
|
||||||
{
|
{
|
||||||
const data = await server.stats.get()
|
const data = await server.stats.get()
|
||||||
|
|
||||||
|
expect(data.totalLocalVideoChannels).to.equal(2)
|
||||||
expect(data.totalLocalDailyActiveVideoChannels).to.equal(1)
|
expect(data.totalLocalDailyActiveVideoChannels).to.equal(1)
|
||||||
expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1)
|
expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1)
|
||||||
expect(data.totalLocalMonthlyActiveVideoChannels).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()
|
const data = await server.stats.get()
|
||||||
|
|
||||||
|
expect(data.totalLocalVideoChannels).to.equal(3)
|
||||||
expect(data.totalLocalDailyActiveVideoChannels).to.equal(1)
|
expect(data.totalLocalDailyActiveVideoChannels).to.equal(1)
|
||||||
expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1)
|
expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1)
|
||||||
expect(data.totalLocalMonthlyActiveVideoChannels).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()
|
const data = await server.stats.get()
|
||||||
|
|
||||||
|
expect(data.totalLocalVideoChannels).to.equal(3)
|
||||||
expect(data.totalLocalDailyActiveVideoChannels).to.equal(2)
|
expect(data.totalLocalDailyActiveVideoChannels).to.equal(2)
|
||||||
expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(2)
|
expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(2)
|
||||||
expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(2)
|
expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(2)
|
||||||
|
|
Loading…
Reference in New Issue