1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 09:32:55 +08:00

Replace BeatmapLeaderboard event flow with realm subscriptions

This commit is contained in:
Dean Herbert 2021-12-17 18:37:28 +09:00
parent 1f9318265e
commit 5dc497e949

View File

@ -44,6 +44,8 @@ namespace osu.Game.Screens.Select.Leaderboards
Scores = null;
UpdateScores();
if (IsLoaded)
refreshRealmSubscription();
}
}
@ -78,6 +80,9 @@ namespace osu.Game.Screens.Select.Leaderboards
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private RealmContextFactory realmContextFactory { get; set; }
[BackgroundDependencyLoader]
private void load()
{
@ -87,9 +92,32 @@ namespace osu.Game.Screens.Select.Leaderboards
if (filterMods)
UpdateScores();
};
}
scoreManager.ItemRemoved += scoreStoreChanged;
scoreManager.ItemUpdated += scoreStoreChanged;
protected override void LoadComplete()
{
base.LoadComplete();
refreshRealmSubscription();
}
private IDisposable scoreSubscription;
private void refreshRealmSubscription()
{
scoreSubscription?.Dispose();
scoreSubscription = null;
if (beatmapInfo == null)
return;
scoreSubscription = realmContextFactory.Context.All<ScoreInfo>().Where(s => s.BeatmapInfo.ID == beatmapInfo.ID).QueryAsyncWithNotifications((_, changes, ___) =>
{
if (changes == null)
return;
RefreshScores();
});
}
protected override void Reset()
@ -212,11 +240,7 @@ namespace osu.Game.Screens.Select.Leaderboards
{
base.Dispose(isDisposing);
if (scoreManager != null)
{
scoreManager.ItemRemoved -= scoreStoreChanged;
scoreManager.ItemUpdated -= scoreStoreChanged;
}
scoreSubscription?.Dispose();
}
}
}