Improved actor mapping in release associations. Storing alias ID in actor release association.

This commit is contained in:
DebaucheryLibrarian 2021-02-17 00:40:20 +01:00
parent 3469da674a
commit c51cd080fa
3 changed files with 28 additions and 4 deletions

View File

@ -682,6 +682,11 @@ exports.up = knex => Promise.resolve()
.inTable('actors')
.onDelete('cascade');
table.integer('alias_id', 12)
.references('id')
.inTable('actors')
.onDelete('cascade');
table.unique(['release_id', 'actor_id']);
table.datetime('created_at')

View File

@ -912,16 +912,32 @@ async function associateActors(releases, batchId) {
const actors = await getOrCreateActors(uniqueBaseActors, batchId);
/*
const actorIdsBySlug = actors.reduce((acc, actor) => ({
...acc,
[actor.slug]: actor.alias_for || actor.id,
}), {});
*/
const actorIdsByEntityIdEntryIdAndSlug = actors.reduce((acc, actor) => ({
...acc,
[actor.entity_id]: {
...acc[actor.entity_id],
[actor.entry_id]: {
...acc[actor.entity_id]?.[actor.entry_id],
[actor.slug]: {
actor_id: actor.alias_for || actor.id,
alias_id: actor.alias_for ? actor.id : null,
},
},
},
}), {});
const releaseActorAssociations = Object.entries(baseActorsByReleaseId)
.map(([releaseId, releaseActors]) => releaseActors
.map(releaseActor => ({
release_id: releaseId,
actor_id: actorIdsBySlug[releaseActor.slug],
...(actorIdsByEntityIdEntryIdAndSlug[releaseActor.entity?.id]?.[releaseActor.entryId]?.[releaseActor.slug] || actorIdsByEntityIdEntryIdAndSlug.null.null[releaseActor.slug]),
})))
.flat();

View File

@ -222,7 +222,11 @@ function actors(release) {
: Math.floor(Math.random() * 3) + 2;
return Array.from({ length }, () => ({
name: faker.name.findName(),
name: faker.name
.findName()
.split(' ')
.slice(0, Math.random() < 0.2 ? 1 : 2) // sometimes only use the first name
.join(' '),
gender: gender(),
}));
}
@ -258,8 +262,7 @@ async function fetchLatest(entity, page, options) {
.limit(faker.random.number({ min: 2, max: 15 }))
.pluck('name');
// release.actors = [...actors(release), null]; // include empty actor to ensure proper handling
release.actors = ['Amber'];
release.actors = [...actors(release), null]; // include empty actor to ensure proper handling
release.title = title(release);
return release;