diff --git a/src/actors.js b/src/actors.js index af4e322e..fc29cfd8 100644 --- a/src/actors.js +++ b/src/actors.js @@ -141,6 +141,17 @@ async function fetchActors(queryObject) { return curateActors(releases); } +async function storeSocialLinks(actor) { + const existingSocialLinks = await knex('social').where({ + domain: 'actors', + target_id: actor.id, + }); + + const newSocialLinks = actor.social.filter(url => !existingSocialLinks.some(existingLink => url === existingLink.url)); + + await knex('social').insert(curateSocialEntries(newSocialLinks, actor)); +} + async function storeActor(actor, scraped = false, scrapeSuccess = false) { const curatedActor = curateActorEntry(actor, scraped, scrapeSuccess); @@ -148,7 +159,7 @@ async function storeActor(actor, scraped = false, scrapeSuccess = false) { .insert(curatedActor) .returning('*'); - await knex('social').insert(curateSocialEntries(actor.social, actor)); + await storeSocialLinks({ ...actor, ...actorEntry }); console.log(`Added new entry for actor '${actor.name}'`); @@ -163,7 +174,7 @@ async function updateActor(actor, scraped = false, scrapeSuccess = false) { .update(curatedActor) .returning('*'); - await knex('social').insert(curateSocialEntries(actor.social, actor)); + await storeSocialLinks({ ...actor, ...curatedActor, ...actorEntry }); console.log(`Updated entry for actor '${actor.name}'`); @@ -181,7 +192,7 @@ function mergeProfiles(profiles, actor) { name: actor ? actor.name : profile.name, description: prevProfile.description || profile.description, gender: prevProfile.gender || profile.gender, - birthdate: Number.isNaN(prevProfile.birthdate) ? profile.birthdate : prevProfile.birthdate, + birthdate: Number.isNaN(Number(prevProfile.birthdate)) ? profile.birthdate : prevProfile.birthdate, birthCountry: prevProfile.birthCountry || profile.birthCountry, residenceCountry: prevProfile.residenceCountry || profile.residenceCountry, birthPlace: prevProfile.birthPlace || profile.birthPlace,