]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix redundancy remove on host redundancy update
authorChocobozzz <me@florianbigard.com>
Thu, 26 Aug 2021 08:00:12 +0000 (10:00 +0200)
committerChocobozzz <me@florianbigard.com>
Thu, 26 Aug 2021 08:01:42 +0000 (10:01 +0200)
server/controllers/api/server/redundancy.ts
server/models/redundancy/video-redundancy.ts
server/tests/api/redundancy/redundancy.ts

index 99d1c762b8d1d8f3bff98259c74f3c122bdbc724..e36c8d2db44fbfa748f36833e863709a715ab946 100644 (file)
@@ -106,9 +106,11 @@ async function updateRedundancy (req: express.Request, res: express.Response) {
 
   await server.save()
 
-  // Async, could be long
-  removeRedundanciesOfServer(server.id)
-    .catch(err => logger.error('Cannot remove redundancy of %s.', server.host, { err }))
+  if (server.redundancyAllowed !== true) {
+    // Async, could be long
+    removeRedundanciesOfServer(server.id)
+      .catch(err => logger.error('Cannot remove redundancy of %s.', server.host, { err }))
+  }
 
   return res.status(HttpStatusCode.NO_CONTENT_204).end()
 }
index d645be24813633dbee752cc3cc408e1fa01255b0..44c17f8e529878eea001a1d2879a853f1a5017c6 100644 (file)
@@ -470,16 +470,34 @@ export class VideoRedundancyModel extends Model<Partial<AttributesOnly<VideoRedu
 
     const query = {
       where: {
-        actorId: actor.id
+        [Op.and]: [
+          {
+            actorId: actor.id
+          },
+          {
+            [Op.or]: [
+              {
+                '$VideoStreamingPlaylist.id$': {
+                  [Op.ne]: null
+                }
+              },
+              {
+                '$VideoFile.id$': {
+                  [Op.ne]: null
+                }
+              }
+            ]
+          }
+        ]
       },
       include: [
         {
-          model: VideoFileModel,
+          model: VideoFileModel.unscoped(),
           required: false,
           include: [ buildVideoInclude() ]
         },
         {
-          model: VideoStreamingPlaylistModel,
+          model: VideoStreamingPlaylistModel.unscoped(),
           required: false,
           include: [ buildVideoInclude() ]
         }
index 3400b1d9adc599e23b93fc8fef8bd7d2a46cf5ae..fe42e5fa874f4f91f1e5986659a562760042c23e 100644 (file)
@@ -49,7 +49,7 @@ async function checkMagnetWebseeds (file: VideoFile, baseWebseeds: string[], ser
   }
 }
 
-async function createSingleServers (strategy: VideoRedundancyStrategy | null, additionalParams: any = {}, withWebtorrent = true) {
+async function createServers (strategy: VideoRedundancyStrategy | null, additionalParams: any = {}, withWebtorrent = true) {
   const strategies: any[] = []
 
   if (strategy !== null) {
@@ -309,7 +309,7 @@ describe('Test videos redundancy', function () {
     before(function () {
       this.timeout(120000)
 
-      return createSingleServers(strategy)
+      return createServers(strategy)
     })
 
     it('Should have 1 webseed on the first video', async function () {
@@ -359,7 +359,7 @@ describe('Test videos redundancy', function () {
     before(function () {
       this.timeout(120000)
 
-      return createSingleServers(strategy)
+      return createServers(strategy)
     })
 
     it('Should have 1 webseed on the first video', async function () {
@@ -384,7 +384,20 @@ describe('Test videos redundancy', function () {
       await checkStatsWith1Redundancy(strategy)
     })
 
-    it('Should unfollow on server 1 and remove duplicated videos', async function () {
+    it('Should unfollow server 3 and keep duplicated videos', async function () {
+      this.timeout(80000)
+
+      await servers[0].follows.unfollow({ target: servers[2] })
+
+      await waitJobs(servers)
+      await wait(5000)
+
+      await check2Webseeds()
+      await check1PlaylistRedundancies()
+      await checkStatsWith1Redundancy(strategy)
+    })
+
+    it('Should unfollow server 2 and remove duplicated videos', async function () {
       this.timeout(80000)
 
       await servers[0].follows.unfollow({ target: servers[1] })
@@ -409,7 +422,7 @@ describe('Test videos redundancy', function () {
     before(function () {
       this.timeout(120000)
 
-      return createSingleServers(strategy, { min_views: 3 })
+      return createServers(strategy, { min_views: 3 })
     })
 
     it('Should have 1 webseed on the first video', async function () {
@@ -480,7 +493,7 @@ describe('Test videos redundancy', function () {
     before(async function () {
       this.timeout(120000)
 
-      await createSingleServers(strategy, { min_views: 3 }, false)
+      await createServers(strategy, { min_views: 3 }, false)
     })
 
     it('Should have 0 playlist redundancy on the first video', async function () {
@@ -542,7 +555,7 @@ describe('Test videos redundancy', function () {
     before(function () {
       this.timeout(120000)
 
-      return createSingleServers(null)
+      return createServers(null)
     })
 
     it('Should have 1 webseed on the first video', async function () {
@@ -621,7 +634,7 @@ describe('Test videos redundancy', function () {
     before(async function () {
       this.timeout(120000)
 
-      await createSingleServers(strategy, { min_lifetime: '7 seconds', min_views: 0 })
+      await createServers(strategy, { min_lifetime: '7 seconds', min_views: 0 })
 
       await enableRedundancyOnServer1()
     })
@@ -663,7 +676,7 @@ describe('Test videos redundancy', function () {
     before(async function () {
       this.timeout(120000)
 
-      await createSingleServers(strategy, { min_lifetime: '7 seconds', min_views: 0 })
+      await createServers(strategy, { min_lifetime: '7 seconds', min_views: 0 })
 
       await enableRedundancyOnServer1()