diff --git a/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs b/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs index f2ab00bead..cd9e765e7f 100644 --- a/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs +++ b/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs @@ -138,8 +138,9 @@ namespace osu.Game.Tests.Beatmaps.IO var set = queryBeatmapSets().First(); foreach (BeatmapInfo b in set.Beatmaps) + Assert.IsTrue(set.Beatmaps.Any(c => c.OnlineBeatmapID == b.OnlineBeatmapID)); - Assert.IsTrue(set.Beatmaps.Count > 0); + Assert.IsTrue(set.Beatmaps.Count > 0); var beatmap = store.GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 0))?.Beatmap; Assert.IsTrue(beatmap?.HitObjects.Count > 0); diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index d364a8fbe4..30da9ceae9 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -59,8 +59,6 @@ namespace osu.Game.Beatmaps private readonly FileStore files; - private readonly OsuDbContext connection; - private readonly RulesetStore rulesets; private readonly BeatmapStore beatmaps; @@ -92,7 +90,6 @@ namespace osu.Game.Beatmaps this.storage = storage; this.files = files; - this.connection = connection; this.rulesets = rulesets; this.api = api; @@ -163,7 +160,7 @@ namespace osu.Game.Beatmaps /// The beatmap to be imported. public BeatmapSetInfo Import(ArchiveReader archiveReader) { - BeatmapSetInfo set = null; + BeatmapSetInfo set; // let's only allow one concurrent import at a time for now. lock (importLock) @@ -181,7 +178,8 @@ namespace osu.Game.Beatmaps // If we have an ID then we already exist in the database. if (beatmapSetInfo.ID != 0) return; - beatmaps.Add(beatmapSetInfo); + lock (beatmaps) + beatmaps.Add(beatmapSetInfo); } /// @@ -272,13 +270,21 @@ namespace osu.Game.Beatmaps /// Delete a beatmap difficulty. /// /// The beatmap difficulty to hide. - public void Hide(BeatmapInfo beatmap) => beatmaps.Hide(beatmap); + public void Hide(BeatmapInfo beatmap) + { + lock (beatmaps) + beatmaps.Hide(beatmap); + } /// /// Restore a beatmap difficulty. /// /// The beatmap difficulty to restore. - public void Restore(BeatmapInfo beatmap) => beatmaps.Restore(beatmap); + public void Restore(BeatmapInfo beatmap) + { + lock (beatmaps) + beatmaps.Restore(beatmap); + } /// /// Returns a to a usable state if it has previously been deleted but not yet purged. @@ -287,7 +293,8 @@ namespace osu.Game.Beatmaps /// The beatmap to restore. public void Undelete(BeatmapSetInfo beatmapSet) { - if (!beatmaps.Undelete(beatmapSet)) return; + lock (beatmaps) + if (!beatmaps.Undelete(beatmapSet)) return; if (!beatmapSet.Protected) files.Reference(beatmapSet.Files.Select(f => f.FileInfo).ToArray()); @@ -361,7 +368,8 @@ namespace osu.Game.Beatmaps /// Results from the provided query. public List QueryBeatmapSets(Func query) { - return beatmaps.QueryAndPopulate(query); + lock (beatmaps) + return beatmaps.QueryAndPopulate(query); } ///