From ba3b87471ede7c00549ef46a779e8c1b5de21045 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 30 Dec 2020 04:17:09 +0100 Subject: [PATCH] Added scene flush. Added temporary media insert log for integer out of range error. --- src/app.js | 6 +++++- src/argv.js | 4 ++++ src/media.js | 4 +++- src/releases.js | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/app.js b/src/app.js index 60571257..b0f9e2c6 100644 --- a/src/app.js +++ b/src/app.js @@ -11,7 +11,7 @@ const { fetchScenes, fetchMovies } = require('./deep'); const { storeScenes, storeMovies, updateReleasesSearch } = require('./store-releases'); const { scrapeActors, flushActors, flushProfiles, interpolateProfiles } = require('./actors'); const { flushEntities } = require('./entities'); -const { deleteScenes, deleteMovies, flushBatches } = require('./releases'); +const { deleteScenes, deleteMovies, flushScenes, flushBatches } = require('./releases'); const { flushOrphanedMedia } = require('./media'); const getFileEntries = require('./utils/file-entries'); @@ -45,6 +45,10 @@ async function init() { await flushBatches(argv.flushBatches); } + if (argv.flushScenes) { + await flushScenes(); + } + if (argv.deleteScenes) { await deleteScenes(argv.deleteScenes); } diff --git a/src/argv.js b/src/argv.js index 4ba2ca0c..3061bcc6 100644 --- a/src/argv.js +++ b/src/argv.js @@ -283,6 +283,10 @@ const { argv } = yargs type: 'array', alias: 'flush-batch', }) + .option('flush-scenes', { + describe: 'Remove all scenes.', + type: 'boolean', + }) .option('delete-scenes', { describe: 'Remove scenes by ID.', type: 'array', diff --git a/src/media.js b/src/media.js index 36d250f8..5bcea1d8 100644 --- a/src/media.js +++ b/src/media.js @@ -657,7 +657,9 @@ async function storeMedias(baseMedias, options) { const newMediaWithEntries = savedMedias.filter(Boolean).map((media, index) => curateMediaEntry(media, index)); const newMediaEntries = newMediaWithEntries.filter(media => media.newEntry).map(media => media.entry); - await bulkInsert('media', newMediaEntries); + console.log('insert error', newMediaEntries.filter(mediaEntry => Object.values(mediaEntry).some(value => Number(value) && Number(value) > 1000000))); + + await bulkInsert('media', newMediaEntries, false); return [...newMediaWithEntries, ...existingHashMedias]; } diff --git a/src/releases.js b/src/releases.js index 7277e8c3..d9ce4cb1 100644 --- a/src/releases.js +++ b/src/releases.js @@ -155,6 +155,27 @@ async function deleteScenes(sceneIds) { return deleteCount; } +async function flushScenes() { + const sceneIds = await knex('releases').select('id').pluck('id'); + + const confirmed = await inquirer.prompt([{ + type: 'confirm', + name: 'flushScenes', + message: `You are about to remove ${sceneIds.length} scenes. Are you sure?`, + default: false, + }]); + + if (!confirmed.flushScenes) { + logger.warn('Confirmation rejected, not flushing scenes'); + return; + } + const deleteCount = await deleteScenes(sceneIds); + + await flushOrphanedMedia(); + + logger.info(`Removed ${deleteCount}/${sceneIds.length} scenes`); +} + async function deleteMovies(movieIds) { if (movieIds.length === 0) { return 0; @@ -208,6 +229,7 @@ module.exports = { fetchScene, fetchScenes, flushBatches, + flushScenes, searchScenes, deleteScenes, deleteMovies,