Added profile interpolate command line argument.

This commit is contained in:
DebaucheryLibrarian 2020-12-30 00:16:05 +01:00
parent 71e76e359a
commit 770e5b75a5
3 changed files with 22 additions and 3 deletions

View File

@ -436,10 +436,17 @@ async function curateProfile(profile, actor) {
} }
} }
async function interpolateProfiles(actorIds) { async function interpolateProfiles(actorIdsOrNames) {
const profiles = await knex('actors_profiles') const profiles = await knex('actors_profiles')
.select('actors_profiles.*', knex.raw('row_to_json(media) as avatar')) .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'); .leftJoin('media', 'actors_profiles.avatar_media_id', 'media.id');
const profilesByActorId = profiles.reduce((acc, profile) => ({ 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]) => { const interpolatedProfiles = Object.entries(profilesByActorId).map(([actorId, actorProfiles]) => {
// group values from each profile // group values from each profile
const valuesByProperty = actorProfiles.reduce((acc, profile) => Object const valuesByProperty = actorProfiles.reduce((acc, profile) => Object
@ -899,4 +908,5 @@ module.exports = {
scrapeActors, scrapeActors,
searchActors, searchActors,
toBaseActors, toBaseActors,
interpolateProfiles,
}; };

View File

@ -9,7 +9,7 @@ const knex = require('./knex');
const fetchUpdates = require('./updates'); const fetchUpdates = require('./updates');
const { fetchScenes, fetchMovies } = require('./deep'); const { fetchScenes, fetchMovies } = require('./deep');
const { storeScenes, storeMovies, updateReleasesSearch } = require('./store-releases'); const { storeScenes, storeMovies, updateReleasesSearch } = require('./store-releases');
const { scrapeActors } = require('./actors'); const { scrapeActors, interpolateProfiles } = require('./actors');
const { flushEntities } = require('./entities'); const { flushEntities } = require('./entities');
const { deleteScenes, deleteMovies, flushBatches } = require('./releases'); const { deleteScenes, deleteMovies, flushBatches } = require('./releases');
const { flushOrphanedMedia } = require('./media'); const { flushOrphanedMedia } = require('./media');
@ -25,6 +25,10 @@ async function init() {
await updateReleasesSearch(); await updateReleasesSearch();
} }
if (argv.interpolateProfiles) {
await interpolateProfiles(argv.interpolateProfiles);
}
if (argv.flushNetworks || argv.flushChannels) { if (argv.flushNetworks || argv.flushChannels) {
await flushEntities(argv.flushNetworks, argv.flushChannels); await flushEntities(argv.flushNetworks, argv.flushChannels);
} }

View File

@ -248,6 +248,11 @@ const { argv } = yargs
type: 'boolean', type: 'boolean',
default: false, default: false,
}) })
.option('interpolate-profiles', {
describe: 'Interpolate actor profiles',
type: 'array',
alias: 'interpolate',
})
.option('flush-orphaned-media', { .option('flush-orphaned-media', {
describe: 'Remove all orphaned media items from database and disk.', describe: 'Remove all orphaned media items from database and disk.',
type: 'array', type: 'array',