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')
.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,
};