diff --git a/osu.Game/Beatmaps/BeatmapImporter.cs b/osu.Game/Beatmaps/BeatmapImporter.cs
index 4f09a73440..bcb1d7f961 100644
--- a/osu.Game/Beatmaps/BeatmapImporter.cs
+++ b/osu.Game/Beatmaps/BeatmapImporter.cs
@@ -141,12 +141,9 @@ namespace osu.Game.Beatmaps
// Handle collections using permissive difficulty name to track difficulties.
foreach (var originalBeatmap in original.Beatmaps)
{
- var updatedBeatmap = updated.Beatmaps.FirstOrDefault(b => b.DifficultyName == originalBeatmap.DifficultyName);
-
- if (updatedBeatmap == null)
- continue;
-
- updatedBeatmap.TransferCollectionsFrom(realm, originalBeatmap.MD5Hash);
+ updated.Beatmaps
+ .FirstOrDefault(b => b.DifficultyName == originalBeatmap.DifficultyName)?
+ .TransferCollectionReferences(realm, originalBeatmap.MD5Hash);
}
}
diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs
index 42461e863c..6f9df1ba7f 100644
--- a/osu.Game/Beatmaps/BeatmapInfo.cs
+++ b/osu.Game/Beatmaps/BeatmapInfo.cs
@@ -214,13 +214,19 @@ namespace osu.Game.Beatmaps
return fileHashX == fileHashY;
}
- public void TransferCollectionsFrom(Realm realm, string oldMd5Hash)
+ ///
+ /// When updating a beatmap, its hashes will change. Collections currently track beatmaps by hash, so they need to be updated.
+ /// This method will handle updating
+ ///
+ /// A realm instance in an active write transaction.
+ /// The previous MD5 hash of the beatmap before update.
+ public void TransferCollectionReferences(Realm realm, string previousMD5Hash)
{
- var collections = realm.All().AsEnumerable().Where(c => c.BeatmapMD5Hashes.Contains(oldMd5Hash));
+ var collections = realm.All().AsEnumerable().Where(c => c.BeatmapMD5Hashes.Contains(previousMD5Hash));
foreach (var c in collections)
{
- c.BeatmapMD5Hashes.Remove(oldMd5Hash);
+ c.BeatmapMD5Hashes.Remove(previousMD5Hash);
c.BeatmapMD5Hashes.Add(MD5Hash);
}
}
diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs
index 9224806301..8ea22e5d67 100644
--- a/osu.Game/Beatmaps/BeatmapManager.cs
+++ b/osu.Game/Beatmaps/BeatmapManager.cs
@@ -330,7 +330,7 @@ namespace osu.Game.Beatmaps
setInfo.CopyChangesToRealm(liveBeatmapSet);
- beatmapInfo.TransferCollectionsFrom(r, oldMd5Hash);
+ beatmapInfo.TransferCollectionReferences(r, oldMd5Hash);
ProcessBeatmap?.Invoke((liveBeatmapSet, false));
});