Added movie flush.

This commit is contained in:
DebaucheryLibrarian 2021-02-05 04:14:13 +01:00
parent a95a159978
commit 80fa953f60
2 changed files with 39 additions and 9 deletions

View File

@ -287,6 +287,10 @@ const { argv } = yargs
describe: 'Remove all scenes.', describe: 'Remove all scenes.',
type: 'boolean', type: 'boolean',
}) })
.option('flush-movies', {
describe: 'Remove all movies.',
type: 'boolean',
})
.option('delete-scenes', { .option('delete-scenes', {
describe: 'Remove scenes by ID.', describe: 'Remove scenes by ID.',
type: 'array', type: 'array',

View File

@ -159,6 +159,24 @@ async function deleteScenes(sceneIds) {
return deleteCount; return deleteCount;
} }
async function deleteMovies(movieIds) {
if (movieIds.length === 0) {
return 0;
}
await knex('movies_scenes')
.whereIn('movie_id', movieIds)
.delete();
const deleteCount = await knex('movies')
.whereIn('id', movieIds)
.delete();
logger.info(`Removed ${deleteCount}/${movieIds.length} movies`);
return deleteCount;
}
async function flushScenes() { async function flushScenes() {
const sceneIds = await knex('releases').select('id').pluck('id'); const sceneIds = await knex('releases').select('id').pluck('id');
@ -180,18 +198,25 @@ async function flushScenes() {
logger.info(`Removed ${deleteCount}/${sceneIds.length} scenes`); logger.info(`Removed ${deleteCount}/${sceneIds.length} scenes`);
} }
async function deleteMovies(movieIds) { async function flushMovies() {
if (movieIds.length === 0) { const movieIds = await knex('movies').select('id').pluck('id');
return 0;
}
const deleteCount = await knex('movies') const confirmed = await inquirer.prompt([{
.whereIn('id', movieIds) type: 'confirm',
.delete(); name: 'flushMovies',
message: `You are about to remove ${movieIds.length} movies. Are you sure?`,
default: false,
}]);
if (!confirmed.flushScenes) {
logger.warn('Confirmation rejected, not flushing scenes');
return;
}
const deleteCount = await deleteMovies(movieIds);
await flushOrphanedMedia();
logger.info(`Removed ${deleteCount}/${movieIds.length} movies`); logger.info(`Removed ${deleteCount}/${movieIds.length} movies`);
return deleteCount;
} }
async function flushBatches(batchIds) { async function flushBatches(batchIds) {
@ -233,6 +258,7 @@ module.exports = {
fetchScene, fetchScene,
fetchScenes, fetchScenes,
flushBatches, flushBatches,
flushMovies,
flushScenes, flushScenes,
searchScenes, searchScenes,
deleteScenes, deleteScenes,