Purge entire video from redundancy

pull/3681/head
Chocobozzz 2021-02-02 08:48:48 +01:00
parent fb7b009d63
commit 89613cb444
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 60 additions and 1 deletions

View 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)
}
}
}

View 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()