From 0b84383d488facc321b100f3280a872ee53e888b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 10 Nov 2020 08:07:21 +0100 Subject: Fix stat file size with HLS --- server/models/video/video-file.ts | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'server/models') diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index a130317f6..d48c9f5d4 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts @@ -269,10 +269,11 @@ export class VideoFileModel extends Model { } static getStats () { - const query: FindOptions = { + const webtorrentFilesQuery: FindOptions = { include: [ { attributes: [], + required: true, model: VideoModel.unscoped(), where: { remote: false @@ -281,10 +282,32 @@ export class VideoFileModel extends Model { ] } - return VideoFileModel.aggregate('size', 'SUM', query) - .then(result => ({ - totalLocalVideoFilesSize: parseAggregateResult(result) - })) + const hlsFilesQuery: FindOptions = { + include: [ + { + attributes: [], + required: true, + model: VideoStreamingPlaylistModel.unscoped(), + include: [ + { + attributes: [], + model: VideoModel.unscoped(), + required: true, + where: { + remote: false + } + } + ] + } + ] + } + + return Promise.all([ + VideoFileModel.aggregate('size', 'SUM', webtorrentFilesQuery), + VideoFileModel.aggregate('size', 'SUM', hlsFilesQuery) + ]).then(([ webtorrentResult, hlsResult ]) => ({ + totalLocalVideoFilesSize: parseAggregateResult(webtorrentResult) + parseAggregateResult(hlsResult) + })) } // Redefine upsert because sequelize does not use an appropriate where clause in the update query with 2 unique indexes -- cgit v1.2.3