1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:03:13 +08:00

Refactor/rename deletion method to read better

This commit is contained in:
Dean Herbert 2022-09-02 16:58:46 +09:00
parent 65baf73d97
commit 605108c938
2 changed files with 16 additions and 17 deletions

View File

@ -364,27 +364,26 @@ namespace osu.Game.Beatmaps
}
/// <summary>
/// Hard-Delete a beatmap difficulty locally.
/// Delete a beatmap difficulty immediately.
/// </summary>
/// <remarks><see cref="Hide"/> is generally preferred as it keeps the local beatmap set in sync with the server.</remarks>
/// <param name="beatmapInfo">The beatmap difficulty to hide.</param>
public void DeleteLocal(BeatmapInfo beatmapInfo)
/// <remarks>
/// There's no undoing this operation, as we don't have a soft-deletion flag on <see cref="BeatmapInfo"/>.
/// This may be a future consideration if there's a user requirement for undeleting support.
/// </remarks>
public void DeleteDifficultyImmediately(BeatmapInfo beatmapInfo)
{
Realm.Run(r =>
{
using (var transaction = r.BeginWrite())
Realm.Write(r =>
{
if (!beatmapInfo.IsManaged)
beatmapInfo = r.Find<BeatmapInfo>(beatmapInfo.ID);
var setInfo = beatmapInfo.BeatmapSet!;
DeleteFile(setInfo, beatmapInfo.File!);
setInfo.Beatmaps.Remove(beatmapInfo);
Debug.Assert(beatmapInfo.BeatmapSet != null);
Debug.Assert(beatmapInfo.File != null);
var liveSetInfo = r.Find<BeatmapSetInfo>(setInfo.ID);
setInfo.CopyChangesToRealm(liveSetInfo);
transaction.Commit();
}
var setInfo = beatmapInfo.BeatmapSet;
DeleteFile(setInfo, beatmapInfo.File);
setInfo.Beatmaps.Remove(beatmapInfo);
});
}

View File

@ -904,7 +904,7 @@ namespace osu.Game.Screens.Edit
var current = playableBeatmap.BeatmapInfo;
if (current is null) return;
beatmapManager.DeleteLocal(current);
beatmapManager.DeleteDifficultyImmediately(current);
switchBeatmapOrExit(current.BeatmapSet);
}