aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-02 08:48:48 +0100
committerChocobozzz <me@florianbigard.com>2021-02-02 08:50:30 +0100
commit89613cb444b4e1601d202153d0ec8635392ec872 (patch)
treeb8a5835253028f563ee9afbd2561032c94ec58b4
parentfb7b009d6368acacade236b74406709851a0eaa5 (diff)
downloadPeerTube-89613cb444b4e1601d202153d0ec8635392ec872.tar.gz
PeerTube-89613cb444b4e1601d202153d0ec8635392ec872.tar.zst
PeerTube-89613cb444b4e1601d202153d0ec8635392ec872.zip
Purge entire video from redundancy
-rw-r--r--server/lib/schedulers/videos-redundancy-scheduler.ts10
-rw-r--r--server/models/redundancy/video-redundancy.ts51
2 files changed, 60 insertions, 1 deletions
diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts
index 82005a2c8..93e76626c 100644
--- a/server/lib/schedulers/videos-redundancy-scheduler.ts
+++ b/server/lib/schedulers/videos-redundancy-scheduler.ts
@@ -301,7 +301,15 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
301 const toDelete = await VideoRedundancyModel.loadOldestLocalExpired(redundancy.strategy, redundancy.minLifetime) 301 const toDelete = await VideoRedundancyModel.loadOldestLocalExpired(redundancy.strategy, redundancy.minLifetime)
302 if (!toDelete) return 302 if (!toDelete) return
303 303
304 await removeVideoRedundancy(toDelete) 304 const videoId = toDelete.VideoFile
305 ? toDelete.VideoFile.videoId
306 : toDelete.VideoStreamingPlaylist.videoId
307
308 const redundancies = await VideoRedundancyModel.listLocalByVideoId(videoId)
309
310 for (const redundancy of redundancies) {
311 await removeVideoRedundancy(redundancy)
312 }
305 } 313 }
306 } 314 }
307 315
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts
index 98c6ff134..74895fe30 100644
--- a/server/models/redundancy/video-redundancy.ts
+++ b/server/models/redundancy/video-redundancy.ts
@@ -185,6 +185,57 @@ export class VideoRedundancyModel extends Model {
185 return VideoRedundancyModel.scope(ScopeNames.WITH_VIDEO).findOne(query) 185 return VideoRedundancyModel.scope(ScopeNames.WITH_VIDEO).findOne(query)
186 } 186 }
187 187
188 static async listLocalByVideoId (videoId: number): Promise<MVideoRedundancyVideo[]> {
189 const actor = await getServerActor()
190
191 const queryStreamingPlaylist = {
192 where: {
193 actorId: actor.id
194 },
195 include: [
196 {
197 model: VideoStreamingPlaylistModel.unscoped(),
198 required: true,
199 include: [
200 {
201 model: VideoModel.unscoped(),
202 required: true,
203 where: {
204 id: videoId
205 }
206 }
207 ]
208 }
209 ]
210 }
211
212 const queryFiles = {
213 where: {
214 actorId: actor.id
215 },
216 include: [
217 {
218 model: VideoFileModel,
219 required: true,
220 include: [
221 {
222 model: VideoModel,
223 required: true,
224 where: {
225 id: videoId
226 }
227 }
228 ]
229 }
230 ]
231 }
232
233 return Promise.all([
234 VideoRedundancyModel.findAll(queryStreamingPlaylist),
235 VideoRedundancyModel.findAll(queryFiles)
236 ]).then(([ r1, r2 ]) => r1.concat(r2))
237 }
238
188 static async loadLocalByStreamingPlaylistId (videoStreamingPlaylistId: number): Promise<MVideoRedundancyVideo> { 239 static async loadLocalByStreamingPlaylistId (videoStreamingPlaylistId: number): Promise<MVideoRedundancyVideo> {
189 const actor = await getServerActor() 240 const actor = await getServerActor()
190 241