From 6df88c949acdd4a8eabd0bf4013c2cb7e38bbd6b Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 15 Mar 2026 07:26:04 -0300 Subject: content: gAIPTracksChunk: rephrase & tighten up secondary releases --- .../generateArtistInfoPageTracksChunk.js | 34 ++++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'src/content/dependencies/generateArtistInfoPageTracksChunk.js') 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 => -- cgit 1.3.0-6-gf8a5