aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-03-13 13:43:26 +0100
committerChocobozzz <me@florianbigard.com>2020-03-13 14:54:00 +0100
commitbaab47ca81742deae15acd671e8c332a4e1d6eb7 (patch)
tree06838db49de28a3adae14934ef2d036e33b3bb8e /server/models
parent8c966daab30dd2bc8fd9792a8e219d94f3d8e67c (diff)
downloadPeerTube-baab47ca81742deae15acd671e8c332a4e1d6eb7.tar.gz
PeerTube-baab47ca81742deae15acd671e8c332a4e1d6eb7.tar.zst
PeerTube-baab47ca81742deae15acd671e8c332a4e1d6eb7.zip
Fix total videos stats
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video/video.ts14
1 files changed, 13 insertions, 1 deletions
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