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

Use asynchronous loading for beatmap carousel again

This commit is contained in:
Dean Herbert 2022-01-19 17:47:46 +09:00
parent 200fcb6f83
commit 2789986699

View File

@ -181,6 +181,11 @@ namespace osu.Game.Screens.Select
RightClickScrollingEnabled.ValueChanged += enabled => Scroll.RightMouseScrollbar = enabled.NewValue;
RightClickScrollingEnabled.TriggerChange();
using (var realm = realmFactory.CreateContext())
{
loadBeatmapSets(getBeatmapSets(realm));
}
}
[Resolved]
@ -190,7 +195,7 @@ namespace osu.Game.Screens.Select
{
base.LoadComplete();
subscriptionSets = realmFactory.Context.All<BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected).QueryAsyncWithNotifications(beatmapSetsChanged);
subscriptionSets = getBeatmapSets(realmFactory.Context).QueryAsyncWithNotifications(beatmapSetsChanged);
subscriptionBeatmaps = realmFactory.Context.All<BeatmapInfo>().Where(b => !b.Hidden).QueryAsyncWithNotifications(beatmapsChanged);
// Can't use main subscriptions because we can't lookup deleted indices.
@ -220,8 +225,29 @@ namespace osu.Game.Screens.Select
if (changes == null)
{
// initial load
loadBeatmapSets(sender);
// During initial population, we must manually account for the fact that our original query was done on an async thread.
// Since then, there may have been imports or deletions.
// Here we manually catch up on any changes.
var populatedSets = new HashSet<Guid>();
foreach (var s in beatmapSets)
populatedSets.Add(s.BeatmapSet.ID);
var realmSets = new HashSet<Guid>();
foreach (var s in sender)
realmSets.Add(s.ID);
foreach (var s in realmSets)
{
if (!populatedSets.Contains(s))
UpdateBeatmapSet(realmFactory.Context.Find<BeatmapSetInfo>(s));
}
foreach (var s in populatedSets)
{
if (!realmSets.Contains(s))
RemoveBeatmapSet(realmFactory.Context.Find<BeatmapSetInfo>(s));
}
return;
}
@ -242,6 +268,8 @@ namespace osu.Game.Screens.Select
UpdateBeatmapSet(sender[i].BeatmapSet);
}
private IRealmCollection<BeatmapSetInfo> getBeatmapSets(Realm realm) => realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected).AsRealmCollection();
public void RemoveBeatmapSet(BeatmapSetInfo beatmapSet) => Schedule(() =>
{
var existingSet = beatmapSets.FirstOrDefault(b => b.BeatmapSet.Equals(beatmapSet));