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 6b93c3dff..615027a7a 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/graph/MusicGraph.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/graph/MusicGraph.kt @@ -137,6 +137,10 @@ private class MusicGraphBuilderImpl : MusicGraph.Builder { } private fun simplifyGenreCluster(cluster: Collection) { + if (cluster.size == 1) { + // Nothing to do. + return + } // All of these genres are semantically equivalent. Pick the most popular variation // and merge all the others into it. val clusterSet = cluster.toMutableSet() @@ -166,6 +170,10 @@ private class MusicGraphBuilderImpl : MusicGraph.Builder { } private fun simplifyArtistCluster(cluster: Collection) { + if (cluster.size == 1) { + // Nothing to do. + return + } val fullMusicBrainzIdCoverage = cluster.all { it.preArtist.musicBrainzId != null } if (fullMusicBrainzIdCoverage) { // All artists have MBIDs, nothing needs to be merged. @@ -225,6 +233,10 @@ private class MusicGraphBuilderImpl : MusicGraph.Builder { } private fun simplifyAlbumCluster(cluster: Collection) { + if (cluster.size == 1) { + // Nothing to do. + return; + } val fullMusicBrainzIdCoverage = cluster.all { it.preAlbum.musicBrainzId != null } if (fullMusicBrainzIdCoverage) { // All albums have MBIDs, nothing needs to be merged. @@ -251,6 +263,10 @@ private class MusicGraphBuilderImpl : MusicGraph.Builder { private fun simplifyAlbumClusterImpl(cluster: Collection) { // All of these albums are semantically equivalent. Pick the most popular variation // and merge all the others into it. + if (cluster.size == 1) { + // Nothing to do. + return + } val clusterSet = cluster.toMutableSet() val dst = clusterSet.maxBy { it.songVertices.size } clusterSet.remove(dst)