Storing original tags.

This commit is contained in:
DebaucheryLibrarian
2021-10-10 00:04:21 +02:00
parent 6c298cd639
commit b6ad2903f3
29 changed files with 27 additions and 11 deletions

View File

@@ -117,22 +117,26 @@ async function getEntityTags(releases) {
function buildReleaseTagAssociations(releases, tagIdsBySlug, entityTagIdsByEntityId, type) {
const tagAssociations = releases
.map((release) => {
const entityTagIds = entityTagIdsByEntityId[release.entity?.id] || [];
const releaseTags = release.tags || [];
const entityTagIds = entityTagIdsByEntityId[release.entity?.id].map(tag => ({ id: tag.id, origin: tag.name })) || [];
const releaseTags = release.tags?.filter(Boolean) || [];
const releaseTagIds = releaseTags.every(tag => typeof tag === 'number')
const releaseTagsWithIds = releaseTags.every(tag => typeof tag === 'number')
? releaseTags // obsolete scraper returned pre-matched tags
: releaseTags.map(tag => tagIdsBySlug[slugify(tag)]);
: releaseTags.map(tag => ({
id: tagIdsBySlug[slugify(tag)],
original: tag,
}));
const tags = [...new Set(
// filter duplicates and empties
releaseTagIds
releaseTagsWithIds
.concat(entityTagIds)
.filter(Boolean),
)]
.map(tagId => ({
.map(tag => ({
[`${type}_id`]: release.id,
tag_id: tagId,
tag_id: tag.id,
original_tag: tag.original,
}));
return tags;