forked from DebaucheryLibrarian/traxxx
Improved actor mapping in release associations. Storing alias ID in actor release association.
This commit is contained in:
parent
3469da674a
commit
c51cd080fa
|
@ -682,6 +682,11 @@ exports.up = knex => Promise.resolve()
|
||||||
.inTable('actors')
|
.inTable('actors')
|
||||||
.onDelete('cascade');
|
.onDelete('cascade');
|
||||||
|
|
||||||
|
table.integer('alias_id', 12)
|
||||||
|
.references('id')
|
||||||
|
.inTable('actors')
|
||||||
|
.onDelete('cascade');
|
||||||
|
|
||||||
table.unique(['release_id', 'actor_id']);
|
table.unique(['release_id', 'actor_id']);
|
||||||
|
|
||||||
table.datetime('created_at')
|
table.datetime('created_at')
|
||||||
|
|
|
@ -912,16 +912,32 @@ async function associateActors(releases, batchId) {
|
||||||
|
|
||||||
const actors = await getOrCreateActors(uniqueBaseActors, batchId);
|
const actors = await getOrCreateActors(uniqueBaseActors, batchId);
|
||||||
|
|
||||||
|
/*
|
||||||
const actorIdsBySlug = actors.reduce((acc, actor) => ({
|
const actorIdsBySlug = actors.reduce((acc, actor) => ({
|
||||||
...acc,
|
...acc,
|
||||||
[actor.slug]: actor.alias_for || actor.id,
|
[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)
|
const releaseActorAssociations = Object.entries(baseActorsByReleaseId)
|
||||||
.map(([releaseId, releaseActors]) => releaseActors
|
.map(([releaseId, releaseActors]) => releaseActors
|
||||||
.map(releaseActor => ({
|
.map(releaseActor => ({
|
||||||
release_id: releaseId,
|
release_id: releaseId,
|
||||||
actor_id: actorIdsBySlug[releaseActor.slug],
|
...(actorIdsByEntityIdEntryIdAndSlug[releaseActor.entity?.id]?.[releaseActor.entryId]?.[releaseActor.slug] || actorIdsByEntityIdEntryIdAndSlug.null.null[releaseActor.slug]),
|
||||||
})))
|
})))
|
||||||
.flat();
|
.flat();
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,11 @@ function actors(release) {
|
||||||
: Math.floor(Math.random() * 3) + 2;
|
: Math.floor(Math.random() * 3) + 2;
|
||||||
|
|
||||||
return Array.from({ length }, () => ({
|
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(),
|
gender: gender(),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -258,8 +262,7 @@ async function fetchLatest(entity, page, options) {
|
||||||
.limit(faker.random.number({ min: 2, max: 15 }))
|
.limit(faker.random.number({ min: 2, max: 15 }))
|
||||||
.pluck('name');
|
.pluck('name');
|
||||||
|
|
||||||
// release.actors = [...actors(release), null]; // include empty actor to ensure proper handling
|
release.actors = [...actors(release), null]; // include empty actor to ensure proper handling
|
||||||
release.actors = ['Amber'];
|
|
||||||
release.title = title(release);
|
release.title = title(release);
|
||||||
|
|
||||||
return release;
|
return release;
|
||||||
|
|
Loading…
Reference in New Issue