From a0ed434360f8b111610d14dcba732c0e86100139 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Thu, 6 Jun 2024 00:20:54 +0200 Subject: [PATCH] Added date range to flush commands. --- src/argv.js | 16 +++++++++++++--- src/entities.js | 33 ++++++++++++++++++++++++++++++--- src/releases.js | 31 ++++++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/src/argv.js b/src/argv.js index b444da43..d7411a21 100755 --- a/src/argv.js +++ b/src/argv.js @@ -4,7 +4,7 @@ const config = require('config'); const yargs = require('yargs'); const moment = require('moment'); -function interpretAfter(after, ignoreIfEmpty = false) { +function interpretDate(after, ignoreIfEmpty = false) { if (!after && ignoreIfEmpty) { return null; } @@ -341,6 +341,14 @@ const { argv } = yargs describe: 'Remove all movies.', type: 'boolean', }) + .option('flush-after', { + describe: 'Only delete scenes release after including', + type: 'string', + }) + .option('flush-before', { + describe: 'Only delete scenes released before including', + type: 'string', + }) .option('delete-actors', { describe: 'Remove actors by ID.', type: 'array', @@ -378,7 +386,9 @@ const { argv } = yargs alias: ['showcase', 'batch-showcased'], default: true, }) - .coerce('after', interpretAfter) - .coerce('actors-update', (after) => interpretAfter(after, true)); + .coerce('after', interpretDate) + .coerce('flush-after', interpretDate) + .coerce('flush-before', interpretDate) + .coerce('actors-update', (after) => interpretDate(after, true)); module.exports = argv; diff --git a/src/entities.js b/src/entities.js index c8af5876..4945c6da 100755 --- a/src/entities.js +++ b/src/entities.js @@ -372,27 +372,54 @@ async function flushEntities(networkSlugs = [], channelSlugs = []) { .clone() .select('releases.id') .distinct('releases.id') - .whereNotNull('releases.id') .from('selected_entities') .leftJoin('releases', 'releases.entity_id', 'selected_entities.id') + .whereNotNull('releases.id') + .modify((builder) => { + if (argv.flushAfter) { + builder.where('effective_date', '>=', argv.flushAfter); + } + + if (argv.flushBefore) { + builder.where('effective_date', '<=', argv.flushBefore); + } + }) .pluck('releases.id'); const movieIds = await entityQuery .clone() .select('movies.id') .distinct('movies.id') - .whereNotNull('movies.id') .from('selected_entities') .leftJoin('movies', 'movies.entity_id', 'selected_entities.id') + .whereNotNull('movies.id') + .modify((builder) => { + if (argv.flushAfter) { + builder.where('effective_date', '>=', argv.flushAfter); + } + + if (argv.flushBefore) { + builder.where('effective_date', '<=', argv.flushBefore); + } + }) .pluck('movies.id'); const serieIds = await entityQuery .clone() .select('series.id') .distinct('series.id') - .whereNotNull('series.id') .from('selected_entities') .leftJoin('series', 'series.entity_id', 'selected_entities.id') + .whereNotNull('series.id') + .modify((builder) => { + if (argv.flushAfter) { + builder.where('date', '>=', argv.flushAfter); + } + + if (argv.flushBefore) { + builder.where('date', '<=', argv.flushBefore); + } + }) .pluck('series.id'); if (sceneIds.length === 0 && movieIds.length === 0 && serieIds.length === 0) { diff --git a/src/releases.js b/src/releases.js index 4e636b43..22b8bd06 100755 --- a/src/releases.js +++ b/src/releases.js @@ -348,7 +348,18 @@ async function deleteSeries(serieIds) { } async function flushScenes() { - const sceneIds = await knex('releases').select('id').pluck('id'); + const sceneIds = await knex('releases') + .select('id') + .modify((builder) => { + if (argv.flushAfter) { + builder.where('effective_date', '>=', argv.flushAfter); + } + + if (argv.flushBefore) { + builder.where('effective_date', '<=', argv.flushBefore); + } + }) + .pluck('id'); const confirmed = await inquirer.prompt([{ type: 'confirm', @@ -421,10 +432,28 @@ async function flushBatches(batchIds) { knex('releases') .select('releases.id') .whereIn('created_batch_id', batchIds) + .modify((builder) => { + if (argv.flushAfter) { + builder.where('effective_date', '>=', argv.flushAfter); + } + + if (argv.flushBefore) { + builder.where('effective_date', '<=', argv.flushBefore); + } + }) .pluck('releases.id'), knex('movies').whereIn('created_batch_id', batchIds) .select('movies.id') .whereIn('created_batch_id', batchIds) + .modify((builder) => { + if (argv.flushAfter) { + builder.where('effective_date', '>=', argv.flushAfter); + } + + if (argv.flushBefore) { + builder.where('effective_date', '<=', argv.flushBefore); + } + }) .pluck('movies.id'), ]);