]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Purge entire video from redundancy
authorChocobozzz <me@florianbigard.com>
Tue, 2 Feb 2021 07:48:48 +0000 (08:48 +0100)
committerChocobozzz <me@florianbigard.com>
Tue, 2 Feb 2021 07:50:30 +0000 (08:50 +0100)
server/lib/schedulers/videos-redundancy-scheduler.ts
server/models/redundancy/video-redundancy.ts

index 82005a2c8c09141a6f096c3cc74a5682533b3bb3..93e76626c3816f42e8ac495347cdaede65334ac1 100644 (file)
@@ -301,7 +301,15 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
       const toDelete = await VideoRedundancyModel.loadOldestLocalExpired(redundancy.strategy, redundancy.minLifetime)
       if (!toDelete) return
 
-      await removeVideoRedundancy(toDelete)
+      const videoId = toDelete.VideoFile
+        ? toDelete.VideoFile.videoId
+        : toDelete.VideoStreamingPlaylist.videoId
+
+      const redundancies = await VideoRedundancyModel.listLocalByVideoId(videoId)
+
+      for (const redundancy of redundancies) {
+        await removeVideoRedundancy(redundancy)
+      }
     }
   }
 
index 98c6ff1349a22ae645fe666366fc1c9e15ec31bb..74895fe3030ffb3fd44927e60acf48340177754f 100644 (file)
@@ -185,6 +185,57 @@ export class VideoRedundancyModel extends Model {
     return VideoRedundancyModel.scope(ScopeNames.WITH_VIDEO).findOne(query)
   }
 
+  static async listLocalByVideoId (videoId: number): Promise<MVideoRedundancyVideo[]> {
+    const actor = await getServerActor()
+
+    const queryStreamingPlaylist = {
+      where: {
+        actorId: actor.id
+      },
+      include: [
+        {
+          model: VideoStreamingPlaylistModel.unscoped(),
+          required: true,
+          include: [
+            {
+              model: VideoModel.unscoped(),
+              required: true,
+              where: {
+                id: videoId
+              }
+            }
+          ]
+        }
+      ]
+    }
+
+    const queryFiles = {
+      where: {
+        actorId: actor.id
+      },
+      include: [
+        {
+          model: VideoFileModel,
+          required: true,
+          include: [
+            {
+              model: VideoModel,
+              required: true,
+              where: {
+                id: videoId
+              }
+            }
+          ]
+        }
+      ]
+    }
+
+    return Promise.all([
+      VideoRedundancyModel.findAll(queryStreamingPlaylist),
+      VideoRedundancyModel.findAll(queryFiles)
+    ]).then(([ r1, r2 ]) => r1.concat(r2))
+  }
+
   static async loadLocalByStreamingPlaylistId (videoStreamingPlaylistId: number): Promise<MVideoRedundancyVideo> {
     const actor = await getServerActor()