From 770e5b75a57fb0017ed08b7b64d1620cc23f1cc4 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 30 Dec 2020 00:16:05 +0100 Subject: [PATCH] Added profile interpolate command line argument. --- src/actors.js | 14 ++++++++++++-- src/app.js | 6 +++++- src/argv.js | 5 +++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/actors.js b/src/actors.js index 13bdeab0..a7fdb217 100644 --- a/src/actors.js +++ b/src/actors.js @@ -436,10 +436,17 @@ async function curateProfile(profile, actor) { } } -async function interpolateProfiles(actorIds) { +async function interpolateProfiles(actorIdsOrNames) { const profiles = await knex('actors_profiles') .select('actors_profiles.*', knex.raw('row_to_json(media) as avatar')) - .whereIn('actor_id', actorIds) + .leftJoin('actors', 'actors.id', 'actors_profiles.actor_id') + .modify((query) => { + if (actorIdsOrNames?.length > 0) { + query + .whereIn('actor_id', actorIdsOrNames.filter(idOrName => typeof idOrName === 'number')) + .orWhereIn('actors.name', actorIdsOrNames.filter(idOrName => typeof idOrName === 'string')); + } + }) .leftJoin('media', 'actors_profiles.avatar_media_id', 'media.id'); const profilesByActorId = profiles.reduce((acc, profile) => ({ @@ -450,6 +457,8 @@ async function interpolateProfiles(actorIds) { ], }), {}); + logger.info(`Interpolating ${profiles.length} profiles from ${Object.keys(profilesByActorId).length} actors`); + const interpolatedProfiles = Object.entries(profilesByActorId).map(([actorId, actorProfiles]) => { // group values from each profile const valuesByProperty = actorProfiles.reduce((acc, profile) => Object @@ -899,4 +908,5 @@ module.exports = { scrapeActors, searchActors, toBaseActors, + interpolateProfiles, }; diff --git a/src/app.js b/src/app.js index 70c68771..37f1c675 100644 --- a/src/app.js +++ b/src/app.js @@ -9,7 +9,7 @@ const knex = require('./knex'); const fetchUpdates = require('./updates'); const { fetchScenes, fetchMovies } = require('./deep'); const { storeScenes, storeMovies, updateReleasesSearch } = require('./store-releases'); -const { scrapeActors } = require('./actors'); +const { scrapeActors, interpolateProfiles } = require('./actors'); const { flushEntities } = require('./entities'); const { deleteScenes, deleteMovies, flushBatches } = require('./releases'); const { flushOrphanedMedia } = require('./media'); @@ -25,6 +25,10 @@ async function init() { await updateReleasesSearch(); } + if (argv.interpolateProfiles) { + await interpolateProfiles(argv.interpolateProfiles); + } + if (argv.flushNetworks || argv.flushChannels) { await flushEntities(argv.flushNetworks, argv.flushChannels); } diff --git a/src/argv.js b/src/argv.js index 0eceb43e..214a4254 100644 --- a/src/argv.js +++ b/src/argv.js @@ -248,6 +248,11 @@ const { argv } = yargs type: 'boolean', default: false, }) + .option('interpolate-profiles', { + describe: 'Interpolate actor profiles', + type: 'array', + alias: 'interpolate', + }) .option('flush-orphaned-media', { describe: 'Remove all orphaned media items from database and disk.', type: 'array',