X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fserver%2Fstats.ts;h=397702548b0e54ff992acf08a75cc972643fd185;hb=20bafcb61bee2a9a10a500908850c9a7d5e3c8c5;hp=85803f69ee87e4559f4dbe56bf14f1688122e649;hpb=d9bdd007d7a1368d2a13127ecb5c0a81a18a8c04;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/server/stats.ts b/server/controllers/api/server/stats.ts index 85803f69e..397702548 100644 --- a/server/controllers/api/server/stats.ts +++ b/server/controllers/api/server/stats.ts @@ -1,47 +1,20 @@ import * as express from 'express' -import { ServerStats } from '../../../../shared/models/server/server-stats.model' +import { StatsManager } from '@server/lib/stat-manager' +import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' 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 { CONFIG, ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' -import { cacheRoute } from '../../../middlewares/cache' +import { cacheRoute } from '../../../middlewares/cache/cache' const statsRouter = express.Router() statsRouter.get('/stats', - asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.STATS)), + cacheRoute(ROUTE_CACHE_LIFETIME.STATS), asyncMiddleware(getStats) ) -async function getStats (req: express.Request, res: express.Response, next: express.NextFunction) { - const { totalLocalVideos, totalLocalVideoViews, totalVideos } = await VideoModel.getStats() - const { totalLocalVideoComments, totalVideoComments } = await VideoCommentModel.getStats() - const { totalUsers } = await UserModel.getStats() - const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats() +async function getStats (_req: express.Request, res: express.Response) { + const data = await StatsManager.Instance.getStats() - const videosRedundancyStats = await Promise.all( - CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.map(r => { - return VideoRedundancyModel.getStats(r.strategy) - .then(stats => Object.assign(stats, { strategy: r.strategy, totalSize: r.size })) - }) - ) - - const data: ServerStats = { - totalLocalVideos, - totalLocalVideoViews, - totalVideos, - totalLocalVideoComments, - totalVideoComments, - totalUsers, - totalInstanceFollowers, - totalInstanceFollowing, - videosRedundancy: videosRedundancyStats - } - - return res.json(data).end() + return res.json(data) } // ---------------------------------------------------------------------------