mirror of
https://github.com/ppy/osu
synced 2025-01-09 23:59:44 +00:00
Update realm queries to use Filter
to allow for indirect property filtering
This commit is contained in:
parent
8461eaab46
commit
de3a338d02
@ -13,6 +13,7 @@ using osu.Game.Online.API;
|
||||
using osu.Game.Online.Leaderboards;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Scoring;
|
||||
using Realms;
|
||||
|
||||
namespace osu.Game.Screens.Select.Carousel
|
||||
{
|
||||
@ -47,13 +48,15 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
scoreSubscription = realmFactory.Context.All<ScoreInfo>().Where(s => s.BeatmapInfo.ID == beatmapInfo.ID).QueryAsyncWithNotifications((_, changes, ___) =>
|
||||
{
|
||||
if (changes == null)
|
||||
return;
|
||||
scoreSubscription = realmFactory.Context.All<ScoreInfo>()
|
||||
.Filter($"{nameof(ScoreInfo.Beatmap)}.{nameof(BeatmapInfo.ID)} = $0", beatmapInfo.ID)
|
||||
.QueryAsyncWithNotifications((_, changes, ___) =>
|
||||
{
|
||||
if (changes == null)
|
||||
return;
|
||||
|
||||
fetchTopScoreRank();
|
||||
});
|
||||
fetchTopScoreRank();
|
||||
});
|
||||
}
|
||||
|
||||
private IDisposable scoreSubscription;
|
||||
@ -84,7 +87,10 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
|
||||
using (var realm = realmFactory.CreateContext())
|
||||
{
|
||||
return realm.All<ScoreInfo>().Where(s => s.UserID == api.LocalUser.Value.Id && s.BeatmapInfoID == beatmapInfo.ID && s.RulesetID == ruleset.Value.ID && !s.DeletePending)
|
||||
return realm.All<ScoreInfo>()
|
||||
.AsEnumerable()
|
||||
// TODO: update to use a realm filter directly (or at least figure out the beatmap part to reduce scope).
|
||||
.Where(s => s.UserID == api.LocalUser.Value.Id && s.BeatmapInfoID == beatmapInfo.ID && s.RulesetID == ruleset.Value.ID && !s.DeletePending)
|
||||
.OrderByDescending(s => s.TotalScore)
|
||||
.FirstOrDefault()
|
||||
?.Rank;
|
||||
|
@ -17,6 +17,7 @@ using osu.Game.Online.Leaderboards;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Scoring;
|
||||
using Realms;
|
||||
|
||||
namespace osu.Game.Screens.Select.Leaderboards
|
||||
{
|
||||
@ -80,9 +81,6 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private RealmContextFactory realmContextFactory { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
@ -111,13 +109,15 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
if (beatmapInfo == null)
|
||||
return;
|
||||
|
||||
scoreSubscription = realmContextFactory.Context.All<ScoreInfo>().Where(s => s.BeatmapInfo.ID == beatmapInfo.ID).QueryAsyncWithNotifications((_, changes, ___) =>
|
||||
{
|
||||
if (changes == null)
|
||||
return;
|
||||
scoreSubscription = realmFactory.Context.All<ScoreInfo>()
|
||||
.Filter($"{nameof(ScoreInfo.Beatmap)}.{nameof(BeatmapInfo.ID)} = $0", beatmapInfo.ID)
|
||||
.QueryAsyncWithNotifications((_, changes, ___) =>
|
||||
{
|
||||
if (changes == null)
|
||||
return;
|
||||
|
||||
RefreshScores();
|
||||
});
|
||||
RefreshScores();
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Reset()
|
||||
|
Loading…
Reference in New Issue
Block a user