aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/server/stats.ts11
-rw-r--r--server/models/video/video.ts14
-rw-r--r--server/tests/api/server/stats.ts12
3 files changed, 30 insertions, 7 deletions
diff --git a/server/controllers/api/server/stats.ts b/server/controllers/api/server/stats.ts
index 6d508a481..f6a85d0c0 100644
--- a/server/controllers/api/server/stats.ts
+++ b/server/controllers/api/server/stats.ts
@@ -26,11 +26,12 @@ async function getStats (req: express.Request, res: express.Response) {
26 const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats() 26 const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats()
27 const { totalLocalVideoFilesSize } = await VideoFileModel.getStats() 27 const { totalLocalVideoFilesSize } = await VideoFileModel.getStats()
28 28
29 const strategies: { strategy: VideoRedundancyStrategyWithManual, size: number }[] = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES 29 const strategies = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES
30 .map(r => ({ 30 .map(r => ({
31 strategy: r.strategy, 31 strategy: r.strategy as VideoRedundancyStrategyWithManual,
32 size: r.size 32 size: r.size
33 })) 33 }))
34
34 strategies.push({ strategy: 'manual', size: null }) 35 strategies.push({ strategy: 'manual', size: null })
35 36
36 const videosRedundancyStats = await Promise.all( 37 const videosRedundancyStats = await Promise.all(
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 958a49e65..0e7505af5 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -125,6 +125,7 @@ import { VideoFile } from '@shared/models/videos/video-file.model'
125import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths' 125import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
126import { ModelCache } from '@server/models/model-cache' 126import { ModelCache } from '@server/models/model-cache'
127import { buildListQuery, BuildVideosQueryOptions, wrapForAPIResults } from './video-query-builder' 127import { buildListQuery, BuildVideosQueryOptions, wrapForAPIResults } from './video-query-builder'
128import { buildNSFWFilter } from '@server/helpers/express-utils'
128 129
129export enum ScopeNames { 130export enum ScopeNames {
130 AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', 131 AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS',
@@ -1301,16 +1302,25 @@ export class VideoModel extends Model<VideoModel> {
1301 remote: false 1302 remote: false
1302 } 1303 }
1303 }) 1304 })
1304 const totalVideos = await VideoModel.count()
1305 1305
1306 let totalLocalVideoViews = await VideoModel.sum('views', { 1306 let totalLocalVideoViews = await VideoModel.sum('views', {
1307 where: { 1307 where: {
1308 remote: false 1308 remote: false
1309 } 1309 }
1310 }) 1310 })
1311
1311 // Sequelize could return null... 1312 // Sequelize could return null...
1312 if (!totalLocalVideoViews) totalLocalVideoViews = 0 1313 if (!totalLocalVideoViews) totalLocalVideoViews = 0
1313 1314
1315 const { total: totalVideos } = await VideoModel.listForApi({
1316 start: 0,
1317 count: 0,
1318 sort: '-publishedAt',
1319 nsfw: buildNSFWFilter(),
1320 includeLocalVideos: true,
1321 withFiles: false
1322 })
1323
1314 return { 1324 return {
1315 totalLocalVideos, 1325 totalLocalVideos,
1316 totalLocalVideoViews, 1326 totalLocalVideoViews,
@@ -1419,6 +1429,8 @@ export class VideoModel extends Model<VideoModel> {
1419 } 1429 }
1420 1430
1421 function getModels () { 1431 function getModels () {
1432 if (options.count === 0) return Promise.resolve([])
1433
1422 const { query, replacements, order } = buildListQuery(VideoModel, options) 1434 const { query, replacements, order } = buildListQuery(VideoModel, options)
1423 const queryModels = wrapForAPIResults(query, replacements, options, order) 1435 const queryModels = wrapForAPIResults(query, replacements, options, order)
1424 1436
diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts
index c207bb5f0..fe956413c 100644
--- a/server/tests/api/server/stats.ts
+++ b/server/tests/api/server/stats.ts
@@ -9,7 +9,7 @@ import {
9 doubleFollow, 9 doubleFollow,
10 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
11 follow, 11 follow,
12 ServerInfo, 12 ServerInfo, unfollow,
13 uploadVideo, 13 uploadVideo,
14 viewVideo, 14 viewVideo,
15 wait 15 wait
@@ -95,6 +95,16 @@ describe('Test stats (excluding redundancy)', function () {
95 expect(data.totalInstanceFollowers).to.equal(0) 95 expect(data.totalInstanceFollowers).to.equal(0)
96 }) 96 })
97 97
98 it('Should have the correct total videos stats after an unfollow', async function () {
99 await unfollow(servers[2].url, servers[2].accessToken, servers[0])
100 await waitJobs(servers)
101
102 const res = await getStats(servers[2].url)
103 const data: ServerStats = res.body
104
105 expect(data.totalVideos).to.equal(0)
106 })
107
98 after(async function () { 108 after(async function () {
99 await cleanupTests(servers) 109 await cleanupTests(servers)
100 }) 110 })