mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 18:52:55 +08:00
Use asynchronous loading for beatmap carousel again
This commit is contained in:
parent
200fcb6f83
commit
2789986699
@ -181,6 +181,11 @@ namespace osu.Game.Screens.Select
|
|||||||
|
|
||||||
RightClickScrollingEnabled.ValueChanged += enabled => Scroll.RightMouseScrollbar = enabled.NewValue;
|
RightClickScrollingEnabled.ValueChanged += enabled => Scroll.RightMouseScrollbar = enabled.NewValue;
|
||||||
RightClickScrollingEnabled.TriggerChange();
|
RightClickScrollingEnabled.TriggerChange();
|
||||||
|
|
||||||
|
using (var realm = realmFactory.CreateContext())
|
||||||
|
{
|
||||||
|
loadBeatmapSets(getBeatmapSets(realm));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
@ -190,7 +195,7 @@ namespace osu.Game.Screens.Select
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
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);
|
subscriptionBeatmaps = realmFactory.Context.All<BeatmapInfo>().Where(b => !b.Hidden).QueryAsyncWithNotifications(beatmapsChanged);
|
||||||
|
|
||||||
// Can't use main subscriptions because we can't lookup deleted indices.
|
// Can't use main subscriptions because we can't lookup deleted indices.
|
||||||
@ -220,8 +225,29 @@ namespace osu.Game.Screens.Select
|
|||||||
|
|
||||||
if (changes == null)
|
if (changes == null)
|
||||||
{
|
{
|
||||||
// initial load
|
// During initial population, we must manually account for the fact that our original query was done on an async thread.
|
||||||
loadBeatmapSets(sender);
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,6 +268,8 @@ namespace osu.Game.Screens.Select
|
|||||||
UpdateBeatmapSet(sender[i].BeatmapSet);
|
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(() =>
|
public void RemoveBeatmapSet(BeatmapSetInfo beatmapSet) => Schedule(() =>
|
||||||
{
|
{
|
||||||
var existingSet = beatmapSets.FirstOrDefault(b => b.BeatmapSet.Equals(beatmapSet));
|
var existingSet = beatmapSets.FirstOrDefault(b => b.BeatmapSet.Equals(beatmapSet));
|
||||||
|
Loading…
Reference in New Issue
Block a user