From 87add0765e9b1cc6757907b3c654cfd52541170f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 27 Jul 2017 00:04:27 +0900 Subject: [PATCH] Initial documentation pass on BeatmapDatabase Also a bit of tidying up. --- .../Tests/TestCasePlaySongSelect.cs | 6 +-- osu.Game/Beatmaps/BeatmapDatabase.cs | 48 ++++++++++--------- osu.Game/Beatmaps/BeatmapStore.cs | 2 +- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs b/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs index a17b873b0d..d27a7507ab 100644 --- a/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs +++ b/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs @@ -33,12 +33,8 @@ public TestCasePlaySongSelect() rulesets = new RulesetDatabase(backingDatabase); store = new BeatmapStore(storage, null, backingDatabase, rulesets); - var sets = new List(); - for (int i = 0; i < 100; i += 10) - sets.Add(createTestBeatmapSet(i)); - - store.Database.Import(sets); + store.Database.Add(createTestBeatmapSet(i)); } Add(songSelect = new PlaySongSelect()); diff --git a/osu.Game/Beatmaps/BeatmapDatabase.cs b/osu.Game/Beatmaps/BeatmapDatabase.cs index 1fd3f5b52f..b05ea815c6 100644 --- a/osu.Game/Beatmaps/BeatmapDatabase.cs +++ b/osu.Game/Beatmaps/BeatmapDatabase.cs @@ -48,38 +48,40 @@ protected override void Prepare(bool reset = false) Connection.CreateTable(); Connection.CreateTable(); - deletePending(); + cleanupPendingDeletions(); } - public void Update(BeatmapSetInfo setInfo) => Connection.Update(setInfo); - - public void Import(IEnumerable beatmapSets) + /// + /// Add a to the database. + /// + /// The beatmap to add. + public void Add(BeatmapSetInfo beatmapSet) { - lock (Connection) - { - Connection.BeginTransaction(); - - foreach (var s in beatmapSets) - { - Connection.InsertOrReplaceWithChildren(s, true); - BeatmapSetAdded?.Invoke(s); - } - - Connection.Commit(); - } + Connection.InsertOrReplaceWithChildren(beatmapSet, true); + BeatmapSetAdded?.Invoke(beatmapSet); } - public bool Delete(BeatmapSetInfo set) + /// + /// Delete a to the database. + /// + /// The beatmap to delete. + /// Whether the beatmap's was changed. + public bool Delete(BeatmapSetInfo beatmapSet) { - if (set.DeletePending) return false; + if (beatmapSet.DeletePending) return false; - set.DeletePending = true; - Connection.Update(set); + beatmapSet.DeletePending = true; + Connection.Update(beatmapSet); - BeatmapSetRemoved?.Invoke(set); + BeatmapSetRemoved?.Invoke(beatmapSet); return true; } + /// + /// Restore a previously deleted . + /// + /// The beatmap to restore. + /// Whether the beatmap's was changed. public bool Undelete(BeatmapSetInfo set) { if (!set.DeletePending) return false; @@ -91,7 +93,7 @@ public bool Undelete(BeatmapSetInfo set) return true; } - private void deletePending() + private void cleanupPendingDeletions() { foreach (var b in GetAllWithChildren(b => b.DeletePending && !b.Protected)) { @@ -119,4 +121,4 @@ private void deletePending() Connection.Query("UPDATE BeatmapSetInfo SET DeletePending = 0 WHERE DeletePending IS NULL"); } } -} \ No newline at end of file +} diff --git a/osu.Game/Beatmaps/BeatmapStore.cs b/osu.Game/Beatmaps/BeatmapStore.cs index 4ee8f8a322..b1c15e87be 100644 --- a/osu.Game/Beatmaps/BeatmapStore.cs +++ b/osu.Game/Beatmaps/BeatmapStore.cs @@ -109,7 +109,7 @@ public BeatmapSetInfo Import(ArchiveReader archiveReader) //If we have an ID then we already exist in the database. if (set.ID == 0) - Database.Import(new[] { set }); + Database.Add(set); return set; }