diff options
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/overviews.ts | 20 | ||||
-rw-r--r-- | server/controllers/api/server/stats.ts | 14 |
2 files changed, 23 insertions, 11 deletions
diff --git a/server/controllers/api/overviews.ts b/server/controllers/api/overviews.ts index cc3cc54a7..8b6773056 100644 --- a/server/controllers/api/overviews.ts +++ b/server/controllers/api/overviews.ts | |||
@@ -21,6 +21,16 @@ export { overviewsRouter } | |||
21 | 21 | ||
22 | // --------------------------------------------------------------------------- | 22 | // --------------------------------------------------------------------------- |
23 | 23 | ||
24 | const buildSamples = memoizee(async function () { | ||
25 | const [ categories, channels, tags ] = await Promise.all([ | ||
26 | VideoModel.getRandomFieldSamples('category', OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD, OVERVIEWS.VIDEOS.SAMPLES_COUNT), | ||
27 | VideoModel.getRandomFieldSamples('channelId', OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD ,OVERVIEWS.VIDEOS.SAMPLES_COUNT), | ||
28 | TagModel.getRandomSamples(OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD, OVERVIEWS.VIDEOS.SAMPLES_COUNT) | ||
29 | ]) | ||
30 | |||
31 | return { categories, channels, tags } | ||
32 | }, { maxAge: MEMOIZE_TTL.OVERVIEWS_SAMPLE }) | ||
33 | |||
24 | // This endpoint could be quite long, but we cache it | 34 | // This endpoint could be quite long, but we cache it |
25 | async function getVideosOverview (req: express.Request, res: express.Response) { | 35 | async function getVideosOverview (req: express.Request, res: express.Response) { |
26 | const attributes = await buildSamples() | 36 | const attributes = await buildSamples() |
@@ -45,16 +55,6 @@ async function getVideosOverview (req: express.Request, res: express.Response) { | |||
45 | return res.json(result) | 55 | return res.json(result) |
46 | } | 56 | } |
47 | 57 | ||
48 | const buildSamples = memoizee(async function () { | ||
49 | const [ categories, channels, tags ] = await Promise.all([ | ||
50 | VideoModel.getRandomFieldSamples('category', OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD, OVERVIEWS.VIDEOS.SAMPLES_COUNT), | ||
51 | VideoModel.getRandomFieldSamples('channelId', OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD ,OVERVIEWS.VIDEOS.SAMPLES_COUNT), | ||
52 | TagModel.getRandomSamples(OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD, OVERVIEWS.VIDEOS.SAMPLES_COUNT) | ||
53 | ]) | ||
54 | |||
55 | return { categories, channels, tags } | ||
56 | }, { maxAge: MEMOIZE_TTL.OVERVIEWS_SAMPLE }) | ||
57 | |||
58 | async function getVideosByTag (tag: string, res: express.Response) { | 58 | async function getVideosByTag (tag: string, res: express.Response) { |
59 | const videos = await getVideos(res, { tagsOneOf: [ tag ] }) | 59 | const videos = await getVideos(res, { tagsOneOf: [ tag ] }) |
60 | 60 | ||
diff --git a/server/controllers/api/server/stats.ts b/server/controllers/api/server/stats.ts index 6f4fe938c..bb6311e81 100644 --- a/server/controllers/api/server/stats.ts +++ b/server/controllers/api/server/stats.ts | |||
@@ -5,10 +5,14 @@ import { UserModel } from '../../../models/account/user' | |||
5 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 5 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
6 | import { VideoModel } from '../../../models/video/video' | 6 | import { VideoModel } from '../../../models/video/video' |
7 | import { VideoCommentModel } from '../../../models/video/video-comment' | 7 | import { VideoCommentModel } from '../../../models/video/video-comment' |
8 | import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' | ||
9 | import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' | ||
10 | import { cacheRoute } from '../../../middlewares/cache' | ||
8 | 11 | ||
9 | const statsRouter = express.Router() | 12 | const statsRouter = express.Router() |
10 | 13 | ||
11 | statsRouter.get('/stats', | 14 | statsRouter.get('/stats', |
15 | asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.STATS)), | ||
12 | asyncMiddleware(getStats) | 16 | asyncMiddleware(getStats) |
13 | ) | 17 | ) |
14 | 18 | ||
@@ -18,6 +22,13 @@ async function getStats (req: express.Request, res: express.Response, next: expr | |||
18 | const { totalUsers } = await UserModel.getStats() | 22 | const { totalUsers } = await UserModel.getStats() |
19 | const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats() | 23 | const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats() |
20 | 24 | ||
25 | const videosRedundancyStats = await Promise.all( | ||
26 | CONFIG.REDUNDANCY.VIDEOS.map(r => { | ||
27 | return VideoRedundancyModel.getStats(r.strategy) | ||
28 | .then(stats => Object.assign(stats, { strategy: r.strategy, totalSize: r.size })) | ||
29 | }) | ||
30 | ) | ||
31 | |||
21 | const data: ServerStats = { | 32 | const data: ServerStats = { |
22 | totalLocalVideos, | 33 | totalLocalVideos, |
23 | totalLocalVideoViews, | 34 | totalLocalVideoViews, |
@@ -26,7 +37,8 @@ async function getStats (req: express.Request, res: express.Response, next: expr | |||
26 | totalVideoComments, | 37 | totalVideoComments, |
27 | totalUsers, | 38 | totalUsers, |
28 | totalInstanceFollowers, | 39 | totalInstanceFollowers, |
29 | totalInstanceFollowing | 40 | totalInstanceFollowing, |
41 | videosRedundancy: videosRedundancyStats | ||
30 | } | 42 | } |
31 | 43 | ||
32 | return res.json(data).end() | 44 | return res.json(data).end() |