From 99afa081bc6ae7f34b2105075bd43e3625434fa8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 15 Dec 2020 13:34:58 +0100 Subject: Add AP stats --- server/controllers/api/server/stats.ts | 56 +++------------------------------- 1 file changed, 5 insertions(+), 51 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/server/stats.ts b/server/controllers/api/server/stats.ts index f07301a04..3aea12450 100644 --- a/server/controllers/api/server/stats.ts +++ b/server/controllers/api/server/stats.ts @@ -1,16 +1,8 @@ import * as express from 'express' -import { ServerStats } from '../../../../shared/models/server/server-stats.model' -import { asyncMiddleware } from '../../../middlewares' -import { UserModel } from '../../../models/account/user' -import { ActorFollowModel } from '../../../models/activitypub/actor-follow' -import { VideoModel } from '../../../models/video/video' -import { VideoCommentModel } from '../../../models/video/video-comment' -import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' +import { StatsManager } from '@server/lib/stat-manager' import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' +import { asyncMiddleware } from '../../../middlewares' import { cacheRoute } from '../../../middlewares/cache' -import { VideoFileModel } from '../../../models/video/video-file' -import { CONFIG } from '../../../initializers/config' -import { VideoRedundancyStrategyWithManual } from '@shared/models' const statsRouter = express.Router() @@ -19,48 +11,10 @@ statsRouter.get('/stats', asyncMiddleware(getStats) ) -async function getStats (req: express.Request, res: express.Response) { - const { totalLocalVideos, totalLocalVideoViews, totalVideos } = await VideoModel.getStats() - const { totalLocalVideoComments, totalVideoComments } = await VideoCommentModel.getStats() - const { totalUsers, totalDailyActiveUsers, totalWeeklyActiveUsers, totalMonthlyActiveUsers } = await UserModel.getStats() - const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats() - const { totalLocalVideoFilesSize } = await VideoFileModel.getStats() - - const strategies = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES - .map(r => ({ - strategy: r.strategy as VideoRedundancyStrategyWithManual, - size: r.size - })) - - strategies.push({ strategy: 'manual', size: null }) - - const videosRedundancyStats = await Promise.all( - strategies.map(r => { - return VideoRedundancyModel.getStats(r.strategy) - .then(stats => Object.assign(stats, { strategy: r.strategy, totalSize: r.size })) - }) - ) - - const data: ServerStats = { - totalLocalVideos, - totalLocalVideoViews, - totalLocalVideoFilesSize, - totalLocalVideoComments, - totalVideos, - totalVideoComments, - - totalUsers, - totalDailyActiveUsers, - totalWeeklyActiveUsers, - totalMonthlyActiveUsers, - - totalInstanceFollowers, - totalInstanceFollowing, - - videosRedundancy: videosRedundancyStats - } +async function getStats (_req: express.Request, res: express.Response) { + const data = await StatsManager.Instance.getStats() - return res.json(data).end() + return res.json(data) } // --------------------------------------------------------------------------- -- cgit v1.2.3