X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-channel.ts;h=b71f5a1971602a100119d63ecc42533e6e06804b;hb=8ca52bcc2c37d457e8b19a237c66b8dd1c00b6b9;hp=9e461b6cadaeae2793a4db89d9e5a20d71938061;hpb=77239b425a8e00822a53c9907415832a473c3eb6;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 9e461b6ca..b71f5a197 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -43,8 +43,14 @@ import { ActorModel, unusedActorAttributesForAPI } from '../actor/actor' import { ActorFollowModel } from '../actor/actor-follow' import { ActorImageModel } from '../actor/actor-image' import { ServerModel } from '../server/server' -import { setAsUpdated } from '../shared' -import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils' +import { + buildServerIdsFollowedBy, + buildTrigramSearchIndex, + createSimilarityAttribute, + getSort, + setAsUpdated, + throwIfNotValid +} from '../shared' import { VideoModel } from './video' import { VideoPlaylistModel } from './video-playlist' @@ -434,42 +440,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 } } @@ -832,6 +837,6 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` } setAsUpdated (transaction?: Transaction) { - return setAsUpdated('videoChannel', this.id, transaction) + return setAsUpdated({ sequelize: this.sequelize, table: 'videoChannel', id: this.id, transaction }) } }