diff options
Diffstat (limited to 'src/content/dependencies')
| -rw-r--r-- | src/content/dependencies/generateArtistInfoPageTracksChunk.js | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunk.js b/src/content/dependencies/generateArtistInfoPageTracksChunk.js index fc5a617e..b3727756 100644 --- a/src/content/dependencies/generateArtistInfoPageTracksChunk.js +++ b/src/content/dependencies/generateArtistInfoPageTracksChunk.js @@ -8,25 +8,35 @@ function countTowardTrackTotals(contribs) { if (!track) return null; + // For secondary releases the goal is to check if the corresponding + // contribution on the main release would be counted toward track totals. + // If any of the artist's contributions on the secondary release don't + // apparently correspond to any on the main release, those will just + // get checked themselves. if (track.isSecondaryRelease) { - const all = + const relevantProperties = + unique(contribs.map(contrib => contrib.thingProperty)); + + const arrays = Object.fromEntries( - unique(contribs.map(contrib => contrib.thingProperty)) - .map(prop => [ - prop, - track.mainReleaseTrack[prop].slice(), - ])); - - contribs = contribs.flatMap(a => { - const array = all[a.thingProperty]; + relevantProperties.map(prop => [ + prop, + track.mainReleaseTrack[prop].slice(), + ])); + + contribs = contribs.map(a => { + const array = arrays[a.thingProperty]; const index = array.findIndex(b => b.artist === a.artist && b.annotation === a.annotation); - if (index === -1) return []; - return array.splice(index, 1); - }).filter(Boolean); + if (index >= 0) { + return array.splice(index, 1).at(0); + } else { + return a; + } + }); } return contribs.some(contrib => |