Refactoring client to reflect database changes.

This commit is contained in:
2019-12-19 04:42:50 +01:00
parent 31aee71edb
commit 1c43884102
9 changed files with 114 additions and 78 deletions

View File

@@ -399,7 +399,7 @@ async function scrapeBasicActors() {
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)),
knex('releases_actors').whereIn('release_id', releases.map(release => release.id)),
]);
const associations = await Promise.map(Object.entries(mappedActors), async ([actorName, releaseIds]) => {
@@ -418,7 +418,7 @@ async function associateActors(mappedActors, releases) {
});
await Promise.all([
knex('actors_associated').insert(associations.flat()),
knex('releases_actors').insert(associations.flat()),
scrapeBasicActors(),
]);
}

View File

@@ -66,20 +66,16 @@ async function associateTags(release, releaseId) {
? await matchTags(release.tags) // scraper returned raw tags
: release.tags; // tags already matched by (outdated) scraper
const associationEntries = await knex('tags_associated')
.where({
domain: 'releases',
target_id: releaseId,
})
const associationEntries = await knex('releases_tags')
.where('release_id', releaseId)
.whereIn('tag_id', tags);
const existingAssociations = new Set(associationEntries.map(association => association.tag_id));
const newAssociations = tags.filter(tagId => !existingAssociations.has(tagId));
await knex('tags_associated').insert(newAssociations.map(tagId => ({
await knex('releases_tags').insert(newAssociations.map(tagId => ({
tag_id: tagId,
domain: 'releases',
target_id: releaseId,
release_id: releaseId,
})));
}