Added scene flush. Added temporary media insert log for integer out of range error.

This commit is contained in:
DebaucheryLibrarian 2020-12-30 04:17:09 +01:00
parent 91746c73e1
commit ba3b87471e
4 changed files with 34 additions and 2 deletions

View File

@ -11,7 +11,7 @@ const { fetchScenes, fetchMovies } = require('./deep');
const { storeScenes, storeMovies, updateReleasesSearch } = require('./store-releases'); const { storeScenes, storeMovies, updateReleasesSearch } = require('./store-releases');
const { scrapeActors, flushActors, flushProfiles, interpolateProfiles } = require('./actors'); const { scrapeActors, flushActors, flushProfiles, interpolateProfiles } = require('./actors');
const { flushEntities } = require('./entities'); const { flushEntities } = require('./entities');
const { deleteScenes, deleteMovies, flushBatches } = require('./releases'); const { deleteScenes, deleteMovies, flushScenes, flushBatches } = require('./releases');
const { flushOrphanedMedia } = require('./media'); const { flushOrphanedMedia } = require('./media');
const getFileEntries = require('./utils/file-entries'); const getFileEntries = require('./utils/file-entries');
@ -45,6 +45,10 @@ async function init() {
await flushBatches(argv.flushBatches); await flushBatches(argv.flushBatches);
} }
if (argv.flushScenes) {
await flushScenes();
}
if (argv.deleteScenes) { if (argv.deleteScenes) {
await deleteScenes(argv.deleteScenes); await deleteScenes(argv.deleteScenes);
} }

View File

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

View File

@ -657,7 +657,9 @@ async function storeMedias(baseMedias, options) {
const newMediaWithEntries = savedMedias.filter(Boolean).map((media, index) => curateMediaEntry(media, index)); const newMediaWithEntries = savedMedias.filter(Boolean).map((media, index) => curateMediaEntry(media, index));
const newMediaEntries = newMediaWithEntries.filter(media => media.newEntry).map(media => media.entry); 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]; return [...newMediaWithEntries, ...existingHashMedias];
} }

View File

@ -155,6 +155,27 @@ async function deleteScenes(sceneIds) {
return deleteCount; 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) { async function deleteMovies(movieIds) {
if (movieIds.length === 0) { if (movieIds.length === 0) {
return 0; return 0;
@ -208,6 +229,7 @@ module.exports = {
fetchScene, fetchScene,
fetchScenes, fetchScenes,
flushBatches, flushBatches,
flushScenes,
searchScenes, searchScenes,
deleteScenes, deleteScenes,
deleteMovies, deleteMovies,