From 0b353d1d8a659140d10b8f7bff3f114698c1a715 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 12 Aug 2019 08:46:46 +0200 Subject: Fix redundancy exceeding the limit --- server/models/redundancy/video-redundancy.ts | 38 ++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'server/models/redundancy') diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index eb2222256..8621a5c6c 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts @@ -325,23 +325,45 @@ export class VideoRedundancyModel extends Model { static async getTotalDuplicated (strategy: VideoRedundancyStrategy) { const actor = await getServerActor() + const redundancyInclude = { + attributes: [], + model: VideoRedundancyModel, + required: true, + where: { + actorId: actor.id, + strategy + } + } - const query: FindOptions = { + const queryFiles: FindOptions = { + include: [ redundancyInclude ] + } + + const queryStreamingPlaylists: FindOptions = { include: [ { attributes: [], - model: VideoRedundancyModel, + model: VideoModel.unscoped(), required: true, - where: { - actorId: actor.id, - strategy - } + include: [ + { + attributes: [], + model: VideoStreamingPlaylistModel.unscoped(), + include: [ + redundancyInclude + ] + } + ] } ] } - return VideoFileModel.aggregate('size', 'SUM', query) - .then(result => parseAggregateResult(result)) + return Promise.all([ + VideoFileModel.aggregate('size', 'SUM', queryFiles), + VideoFileModel.aggregate('size', 'SUM', queryStreamingPlaylists) + ]).then(([ r1, r2 ]) => { + return parseAggregateResult(r1) + parseAggregateResult(r2) + }) } static async listLocalExpired () { -- cgit v1.2.3