From a1d62c2a0898dce3a8b0841d626bf59b463c3b0c Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Mon, 10 Feb 2025 15:07:26 -0700 Subject: [PATCH] musikr: fix dupliate artist vertices when melding --- .../org/oxycblt/musikr/graph/MusicGraph.kt | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/musikr/src/main/java/org/oxycblt/musikr/graph/MusicGraph.kt b/musikr/src/main/java/org/oxycblt/musikr/graph/MusicGraph.kt index 9496ab961..0d0e6104f 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/graph/MusicGraph.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/graph/MusicGraph.kt @@ -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)