]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/stat-manager.ts
Convert followers/following in raw SQL queries
[github/Chocobozzz/PeerTube.git] / server / lib / stat-manager.ts
index 547d7a56b57b5338e3a426c123c1b3cf314b5e68..03063793d8121695bb5864755086545d80021341 100644 (file)
@@ -1,10 +1,13 @@
+import { mapSeries } from 'bluebird'
 import { CONFIG } from '@server/initializers/config'
-import { UserModel } from '@server/models/account/user'
-import { ActorFollowModel } from '@server/models/activitypub/actor-follow'
+import { ActorFollowModel } from '@server/models/actor/actor-follow'
 import { VideoRedundancyModel } from '@server/models/redundancy/video-redundancy'
+import { UserModel } from '@server/models/user/user'
 import { VideoModel } from '@server/models/video/video'
+import { VideoChannelModel } from '@server/models/video/video-channel'
 import { VideoCommentModel } from '@server/models/video/video-comment'
 import { VideoFileModel } from '@server/models/video/video-file'
+import { VideoPlaylistModel } from '@server/models/video/video-playlist'
 import { ActivityType, ServerStats, VideoRedundancyStrategyWithManual } from '@shared/models'
 
 class StatsManager {
@@ -46,21 +49,36 @@ class StatsManager {
     const { totalUsers, totalDailyActiveUsers, totalWeeklyActiveUsers, totalMonthlyActiveUsers } = await UserModel.getStats()
     const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats()
     const { totalLocalVideoFilesSize } = await VideoFileModel.getStats()
+    const {
+      totalLocalVideoChannels,
+      totalLocalDailyActiveVideoChannels,
+      totalLocalWeeklyActiveVideoChannels,
+      totalLocalMonthlyActiveVideoChannels
+    } = await VideoChannelModel.getStats()
+    const { totalLocalPlaylists } = await VideoPlaylistModel.getStats()
 
     const videosRedundancyStats = await this.buildRedundancyStats()
 
     const data: ServerStats = {
+      totalUsers,
+      totalDailyActiveUsers,
+      totalWeeklyActiveUsers,
+      totalMonthlyActiveUsers,
+
       totalLocalVideos,
       totalLocalVideoViews,
-      totalLocalVideoFilesSize,
       totalLocalVideoComments,
+      totalLocalVideoFilesSize,
+
       totalVideos,
       totalVideoComments,
 
-      totalUsers,
-      totalDailyActiveUsers,
-      totalWeeklyActiveUsers,
-      totalMonthlyActiveUsers,
+      totalLocalVideoChannels,
+      totalLocalDailyActiveVideoChannels,
+      totalLocalWeeklyActiveVideoChannels,
+      totalLocalMonthlyActiveVideoChannels,
+
+      totalLocalPlaylists,
 
       totalInstanceFollowers,
       totalInstanceFollowing,
@@ -89,12 +107,10 @@ class StatsManager {
 
     strategies.push({ strategy: 'manual', size: null })
 
-    return Promise.all(
-      strategies.map(r => {
-        return VideoRedundancyModel.getStats(r.strategy)
-          .then(stats => Object.assign(stats, { strategy: r.strategy, totalSize: r.size }))
-      })
-    )
+    return mapSeries(strategies, r => {
+      return VideoRedundancyModel.getStats(r.strategy)
+        .then(stats => Object.assign(stats, { strategy: r.strategy, totalSize: r.size }))
+    })
   }
 
   private buildAPPerType () {