Added orphaned media flush and batch release flush.
This commit is contained in:
42
src/media.js
42
src/media.js
@@ -747,7 +747,49 @@ async function associateAvatars(profiles) {
|
||||
return profilesWithAvatarIds;
|
||||
}
|
||||
|
||||
async function flushOrphanedMedia() {
|
||||
const orphanedMedia = await knex('media')
|
||||
.where('is_sfw', false)
|
||||
.whereNotExists(
|
||||
knex
|
||||
.from(
|
||||
knex('tags_posters')
|
||||
.select('media_id')
|
||||
.unionAll(
|
||||
knex('tags_photos').select('media_id'),
|
||||
knex('releases_posters').select('media_id'),
|
||||
knex('releases_photos').select('media_id'),
|
||||
knex('releases_trailers').select('media_id'),
|
||||
knex('releases_teasers').select('media_id'),
|
||||
knex('movies_covers').select('media_id'),
|
||||
knex('movies_trailers').select('media_id'),
|
||||
knex('actors_avatars').select('media_id'),
|
||||
knex('actors_photos').select('media_id'),
|
||||
knex('clips_photos').select('media_id'),
|
||||
knex('clips_posters').select('media_id'),
|
||||
)
|
||||
.as('associations'),
|
||||
)
|
||||
.whereRaw('associations.media_id = media.id'),
|
||||
)
|
||||
.returning(['media.path', 'media.thumbnail', 'media.lazy'])
|
||||
.delete();
|
||||
|
||||
await Promise.all(orphanedMedia.map(media => Promise.all([
|
||||
fsPromises.unlink(path.join(config.media.path, media.path)).catch(() => { /* probably file not found */ }),
|
||||
fsPromises.unlink(path.join(config.media.path, media.thumbnail)).catch(() => { /* probably file not found */ }),
|
||||
fsPromises.unlink(path.join(config.media.path, media.lazy)).catch(() => { /* probably file not found */ }),
|
||||
])));
|
||||
|
||||
logger.info(`Removed ${orphanedMedia.length} media files from database and disk`);
|
||||
|
||||
await fsPromises.rmdir(path.join(config.media.path, 'temp'), { recursive: true });
|
||||
|
||||
logger.info('Removed temporary media directory');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
associateAvatars,
|
||||
associateReleaseMedia,
|
||||
flushOrphanedMedia,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user