Initial documentation pass on BeatmapDatabase

Also a bit of tidying up.
This commit is contained in:
Dean Herbert 2017-07-27 00:04:27 +09:00
parent 07d4d2dbe4
commit 87add0765e
3 changed files with 27 additions and 29 deletions

View File

@ -33,12 +33,8 @@ namespace osu.Desktop.VisualTests.Tests
rulesets = new RulesetDatabase(backingDatabase);
store = new BeatmapStore(storage, null, backingDatabase, rulesets);
var sets = new List<BeatmapSetInfo>();
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());

View File

@ -48,38 +48,40 @@ namespace osu.Game.Beatmaps
Connection.CreateTable<BeatmapSetFileInfo>();
Connection.CreateTable<BeatmapInfo>();
deletePending();
cleanupPendingDeletions();
}
public void Update(BeatmapSetInfo setInfo) => Connection.Update(setInfo);
public void Import(IEnumerable<BeatmapSetInfo> beatmapSets)
/// <summary>
/// Add a <see cref="BeatmapSetInfo"/> to the database.
/// </summary>
/// <param name="beatmapSet">The beatmap to add.</param>
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)
/// <summary>
/// Delete a <see cref="BeatmapSetInfo"/> to the database.
/// </summary>
/// <param name="beatmapSet">The beatmap to delete.</param>
/// <returns>Whether the beatmap's <see cref="BeatmapSetInfo.DeletePending"/> was changed.</returns>
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;
}
/// <summary>
/// Restore a previously deleted <see cref="BeatmapSetInfo"/>.
/// </summary>
/// <param name="beatmapSet">The beatmap to restore.</param>
/// <returns>Whether the beatmap's <see cref="BeatmapSetInfo.DeletePending"/> was changed.</returns>
public bool Undelete(BeatmapSetInfo set)
{
if (!set.DeletePending) return false;
@ -91,7 +93,7 @@ namespace osu.Game.Beatmaps
return true;
}
private void deletePending()
private void cleanupPendingDeletions()
{
foreach (var b in GetAllWithChildren<BeatmapSetInfo>(b => b.DeletePending && !b.Protected))
{
@ -119,4 +121,4 @@ namespace osu.Game.Beatmaps
Connection.Query<BeatmapSetInfo>("UPDATE BeatmapSetInfo SET DeletePending = 0 WHERE DeletePending IS NULL");
}
}
}
}

View File

@ -109,7 +109,7 @@ namespace osu.Game.Beatmaps
//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;
}