1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 01:27:29 +08:00

Fix beatmap restore/undelete flows

This commit is contained in:
Dean Herbert 2022-01-11 23:04:36 +09:00
parent 46206f70d6
commit 72656ae01e
2 changed files with 21 additions and 23 deletions

View File

@ -147,6 +147,18 @@ namespace osu.Game.Beatmaps
}
}
public void RestoreAll()
{
using (var realm = contextFactory.CreateContext())
using (var transaction = realm.BeginWrite())
{
foreach (var beatmap in realm.All<BeatmapInfo>().Where(b => b.Hidden))
beatmap.Hidden = false;
transaction.Commit();
}
}
/// <summary>
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s.
/// </summary>
@ -168,17 +180,6 @@ namespace osu.Game.Beatmaps
return context.All<BeatmapSetInfo>().FirstOrDefault(query)?.ToLive(contextFactory);
}
/// <summary>
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s.
/// </summary>
/// <param name="query">The query.</param>
/// <returns>Results from the provided query.</returns>
public IQueryable<BeatmapInfo> QueryBeatmaps(Expression<Func<BeatmapInfo, bool>> query)
{
using (var context = contextFactory.CreateContext())
return context.All<BeatmapInfo>().Where(query);
}
#region Delegation to BeatmapModelManager (methods which previously existed locally).
/// <summary>
@ -247,6 +248,12 @@ namespace osu.Game.Beatmaps
}
}
public void UndeleteAll()
{
using (var context = contextFactory.CreateContext())
beatmapModelManager.Undelete(context.All<BeatmapSetInfo>().Where(s => s.DeletePending).ToList());
}
public void Undelete(List<BeatmapSetInfo> items, bool silent = false)
{
beatmapModelManager.Undelete(items, silent);

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using osu.Framework.Allocation;
@ -106,10 +105,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
dialogOverlay?.Push(new MassDeleteConfirmationDialog(() =>
{
deleteSkinsButton.Enabled.Value = false;
Task.Run(() =>
{
skins.Delete();
}).ContinueWith(t => Schedule(() => deleteSkinsButton.Enabled.Value = true));
Task.Run(() => skins.Delete()).ContinueWith(t => Schedule(() => deleteSkinsButton.Enabled.Value = true));
}));
}
});
@ -147,11 +143,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
Action = () =>
{
restoreButton.Enabled.Value = false;
Task.Run(() =>
{
foreach (var b in beatmaps.QueryBeatmaps(b => b.Hidden).ToList())
beatmaps.Restore(b);
}).ContinueWith(t => Schedule(() => restoreButton.Enabled.Value = true));
Task.Run(beatmaps.RestoreAll).ContinueWith(t => Schedule(() => restoreButton.Enabled.Value = true));
}
},
undeleteButton = new SettingsButton
@ -160,8 +152,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
Action = () =>
{
undeleteButton.Enabled.Value = false;
// TODO: reimplement similar to SkinManager?
// Task.Run(() => beatmaps.Undelete(beatmaps.QueryBeatmapSets(b => b.DeletePending).ToList())).ContinueWith(t => Schedule(() => undeleteButton.Enabled.Value = true));
Task.Run(beatmaps.UndeleteAll).ContinueWith(t => Schedule(() => undeleteButton.Enabled.Value = true));
}
},
});