From 0b353d1d8a659140d10b8f7bff3f114698c1a715 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 12 Aug 2019 08:46:46 +0200 Subject: [PATCH] Fix redundancy exceeding the limit --- client/proxy.config.json | 4 ++ .../schedulers/videos-redundancy-scheduler.ts | 5 ++- server/models/redundancy/video-redundancy.ts | 38 +++++++++++++++---- server/tests/api/videos/multiple-servers.ts | 6 +-- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/client/proxy.config.json b/client/proxy.config.json index 81a0fc4c1..e7070522a 100644 --- a/client/proxy.config.json +++ b/client/proxy.config.json @@ -15,6 +15,10 @@ "target": "http://localhost:9000", "secure": false }, + "/lazy-static": { + "target": "http://localhost:9000", + "secure": false + }, "/socket.io": { "target": "ws://localhost:9000", "secure": false, diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts index 90caed96d..04f601bfb 100644 --- a/server/lib/schedulers/videos-redundancy-scheduler.ts +++ b/server/lib/schedulers/videos-redundancy-scheduler.ts @@ -105,7 +105,10 @@ export class VideosRedundancyScheduler extends AbstractScheduler { private async extendsRedundancy (redundancyModel: VideoRedundancyModel) { const redundancy = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.find(s => s.strategy === redundancyModel.strategy) // Redundancy strategy disabled, remove our redundancy instead of extending expiration - if (!redundancy) await removeVideoRedundancy(redundancyModel) + if (!redundancy) { + await removeVideoRedundancy(redundancyModel) + return + } await this.extendsExpirationOf(redundancyModel, redundancy.minLifetime) } 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 () { diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 651765776..0169498e9 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -508,10 +508,8 @@ describe('Test multiple servers', function () { await wait(1000) - await Promise.all([ - viewVideo(servers[2].url, localVideosServer3[0]), - viewVideo(servers[2].url, localVideosServer3[0]) - ]) + await viewVideo(servers[2].url, localVideosServer3[0]) + await viewVideo(servers[2].url, localVideosServer3[0]) await waitJobs(servers) -- 2.41.0