From baab47ca81742deae15acd671e8c332a4e1d6eb7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 13 Mar 2020 13:43:26 +0100 Subject: Fix total videos stats --- server/models/video/video.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'server/models/video/video.ts') 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' import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths' import { ModelCache } from '@server/models/model-cache' import { buildListQuery, BuildVideosQueryOptions, wrapForAPIResults } from './video-query-builder' +import { buildNSFWFilter } from '@server/helpers/express-utils' export enum ScopeNames { AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', @@ -1301,16 +1302,25 @@ export class VideoModel extends Model { remote: false } }) - const totalVideos = await VideoModel.count() let totalLocalVideoViews = await VideoModel.sum('views', { where: { remote: false } }) + // Sequelize could return null... if (!totalLocalVideoViews) totalLocalVideoViews = 0 + const { total: totalVideos } = await VideoModel.listForApi({ + start: 0, + count: 0, + sort: '-publishedAt', + nsfw: buildNSFWFilter(), + includeLocalVideos: true, + withFiles: false + }) + return { totalLocalVideos, totalLocalVideoViews, @@ -1419,6 +1429,8 @@ export class VideoModel extends Model { } function getModels () { + if (options.count === 0) return Promise.resolve([]) + const { query, replacements, order } = buildListQuery(VideoModel, options) const queryModels = wrapForAPIResults(query, replacements, options, order) -- cgit v1.2.3