musikr: fix dupliate artist vertices when melding

This commit is contained in:
Alexander Capehart 2025-02-10 15:07:26 -07:00
parent 3d154ea66c
commit a1d62c2a08
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -243,14 +243,22 @@ private class MusicGraphBuilderImpl : MusicGraph.Builder {
dst.genreVertices.addAll(src.genreVertices)
// Update all songs, albums, and genres to point to the relevant artist.
src.songVertices.forEach {
val index = it.artistVertices.indexOf(src)
check(index >= 0) { "Illegal state: directed edge between artist and song" }
it.artistVertices[index] = dst
// There can be duplicate artist vertices that we need to
// all replace when melding.
for (idx in it.artistVertices.indices) {
if (it.artistVertices[idx] == src) {
it.artistVertices[idx] = dst
}
}
}
src.albumVertices.forEach {
val index = it.artistVertices.indexOf(src)
check(index >= 0) { "Illegal state: directed edge between artist and album" }
it.artistVertices[index] = dst
// There can be duplicate artist vertices that we need to
// all replace when melding.
for (idx in it.artistVertices.indices) {
if (it.artistVertices[idx] == src) {
it.artistVertices[idx] = dst
}
}
}
src.genreVertices.forEach {
it.artistVertices.remove(src)