- static listForApi (actorId: number, start: number, count: number, sort: string) {
- const query = {
- offset: start,
- limit: count,
- order: getSort(sort)
+ static async getStats () {
+
+ function getActiveVideoChannels (days: number) {
+ const options = {
+ type: QueryTypes.SELECT as QueryTypes.SELECT,
+ raw: true
+ }
+
+ 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"`
+
+ return VideoChannelModel.sequelize.query<{ count: string }>(query, options)
+ .then(r => parseInt(r[0].count, 10))