Move tag posters and photos to media database.
This commit is contained in:
@@ -375,28 +375,31 @@ async function scrapeBasicActors() {
|
||||
return scrapeActors(basicActors.map(actor => actor.name));
|
||||
}
|
||||
|
||||
async function associateActors(release, releaseId) {
|
||||
const actorEntries = await knex('actors').whereIn('name', release.actors);
|
||||
|
||||
const newActors = release.actors
|
||||
.map(actorName => actorName.trim())
|
||||
.filter(actorName => !actorEntries.some(actor => actor.name === actorName));
|
||||
|
||||
const [newActorEntries, associatedActors] = await Promise.all([
|
||||
Promise.all(newActors.map(async actorName => storeActor({ name: actorName }))),
|
||||
knex('actors_associated').where('release_id', releaseId),
|
||||
async function associateActors(mappedActors, releases) {
|
||||
const [existingActorEntries, existingAssociationEntries] = await Promise.all([
|
||||
knex('actors').whereIn('name', Object.keys(mappedActors)),
|
||||
knex('actors_associated').whereIn('release_id', releases.map(release => release.id)),
|
||||
]);
|
||||
|
||||
const newlyAssociatedActors = actorEntries
|
||||
.concat(newActorEntries)
|
||||
.filter(actorEntry => !associatedActors.some(actor => actorEntry.id === actor.id))
|
||||
.map(actor => ({
|
||||
release_id: releaseId,
|
||||
actor_id: actor.id,
|
||||
}));
|
||||
const associations = await Promise.map(Object.entries(mappedActors), async ([actorName, releaseIds]) => {
|
||||
const actorEntry = existingActorEntries.find(actor => actor.name === actorName)
|
||||
|| await storeActor({ name: actorName });
|
||||
|
||||
await knex('actors_associated')
|
||||
.insert(newlyAssociatedActors);
|
||||
return releaseIds
|
||||
.map(releaseId => ({
|
||||
release_id: releaseId,
|
||||
actor_id: actorEntry.id,
|
||||
}))
|
||||
.filter(association => !existingAssociationEntries
|
||||
// remove associations already in database
|
||||
.some(associationEntry => associationEntry.actor_id === association.actor_id
|
||||
&& associationEntry.release_id === association.release_id));
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
knex('actors_associated').insert(associations.flat()),
|
||||
scrapeBasicActors(),
|
||||
]);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user