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

Update all usages of QueryAsyncWithNotifications to use new Register pathway

This commit is contained in:
Dean Herbert 2022-01-23 19:50:29 +09:00
parent 61cef42be9
commit e9e3e024a1
9 changed files with 44 additions and 46 deletions

View File

@ -55,13 +55,12 @@ namespace osu.Game.Input.Bindings
protected override void LoadComplete() protected override void LoadComplete()
{ {
realmSubscription = realmFactory.Register(realm => queryRealmKeyBindings() realmSubscription = realmFactory.Register(realm => queryRealmKeyBindings(), (sender, changes, error) =>
.QueryAsyncWithNotifications((sender, changes, error) =>
{ {
// The first fire of this is a bit redundant as this is being called in base.LoadComplete, // The first fire of this is a bit redundant as this is being called in base.LoadComplete,
// but this is safest in case the subscription is restored after a context recycle. // but this is safest in case the subscription is restored after a context recycle.
ReloadMappings(); ReloadMappings();
})); });
base.LoadComplete(); base.LoadComplete();
} }

View File

@ -42,7 +42,7 @@ namespace osu.Game.Online
// Used to interact with manager classes that don't support interface types. Will eventually be replaced. // Used to interact with manager classes that don't support interface types. Will eventually be replaced.
var beatmapSetInfo = new BeatmapSetInfo { OnlineID = TrackedItem.OnlineID }; var beatmapSetInfo = new BeatmapSetInfo { OnlineID = TrackedItem.OnlineID };
realmSubscription = realmContextFactory.Register(realm => realm.All<BeatmapSetInfo>().Where(s => s.OnlineID == TrackedItem.OnlineID && !s.DeletePending).QueryAsyncWithNotifications((items, changes, ___) => realmSubscription = realmContextFactory.Register(realm => realm.All<BeatmapSetInfo>().Where(s => s.OnlineID == TrackedItem.OnlineID && !s.DeletePending), (items, changes, ___) =>
{ {
if (items.Any()) if (items.Any())
Schedule(() => UpdateState(DownloadState.LocallyAvailable)); Schedule(() => UpdateState(DownloadState.LocallyAvailable));
@ -54,7 +54,7 @@ namespace osu.Game.Online
attachDownload(Downloader.GetExistingDownload(beatmapSetInfo)); attachDownload(Downloader.GetExistingDownload(beatmapSetInfo));
}); });
} }
})); });
} }
private void downloadBegan(ArchiveDownloadRequest<IBeatmapSetInfo> request) => Schedule(() => private void downloadBegan(ArchiveDownloadRequest<IBeatmapSetInfo> request) => Schedule(() =>

View File

@ -78,13 +78,13 @@ namespace osu.Game.Online.Rooms
// handles changes to hash that didn't occur from the import process (ie. a user editing the beatmap in the editor, somehow). // handles changes to hash that didn't occur from the import process (ie. a user editing the beatmap in the editor, somehow).
realmSubscription?.Dispose(); realmSubscription?.Dispose();
realmSubscription = realmContextFactory.Register(realm => filteredBeatmaps().QueryAsyncWithNotifications((items, changes, ___) => realmSubscription = realmContextFactory.Register(realm => filteredBeatmaps(), (items, changes, ___) =>
{ {
if (changes == null) if (changes == null)
return; return;
Scheduler.AddOnce(updateAvailability); Scheduler.AddOnce(updateAvailability);
})); });
}, true); }, true);
} }

View File

@ -47,7 +47,7 @@ namespace osu.Game.Online
Downloader.DownloadBegan += downloadBegan; Downloader.DownloadBegan += downloadBegan;
Downloader.DownloadFailed += downloadFailed; Downloader.DownloadFailed += downloadFailed;
realmSubscription = realmContextFactory.Register(realm => realm.All<ScoreInfo>().Where(s => ((s.OnlineID > 0 && s.OnlineID == TrackedItem.OnlineID) || s.Hash == TrackedItem.Hash) && !s.DeletePending).QueryAsyncWithNotifications((items, changes, ___) => realmSubscription = realmContextFactory.Register(realm => realm.All<ScoreInfo>().Where(s => ((s.OnlineID > 0 && s.OnlineID == TrackedItem.OnlineID) || s.Hash == TrackedItem.Hash) && !s.DeletePending), (items, changes, ___) =>
{ {
if (items.Any()) if (items.Any())
Schedule(() => UpdateState(DownloadState.LocallyAvailable)); Schedule(() => UpdateState(DownloadState.LocallyAvailable));
@ -59,7 +59,7 @@ namespace osu.Game.Online
attachDownload(Downloader.GetExistingDownload(scoreInfo)); attachDownload(Downloader.GetExistingDownload(scoreInfo));
}); });
} }
})); });
} }
private void downloadBegan(ArchiveDownloadRequest<IScoreInfo> request) => Schedule(() => private void downloadBegan(ArchiveDownloadRequest<IScoreInfo> request) => Schedule(() =>

View File

@ -93,7 +93,7 @@ namespace osu.Game.Overlays
foreach (var s in availableBeatmaps) foreach (var s in availableBeatmaps)
beatmapSets.Add(s.Detach()); beatmapSets.Add(s.Detach());
beatmapSubscription = realmFactory.Register(realm => availableBeatmaps.QueryAsyncWithNotifications(beatmapsChanged)); beatmapSubscription = realmFactory.Register(realm => availableBeatmaps, beatmapsChanged);
} }
private void beatmapsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet changes, Exception error) private void beatmapsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet changes, Exception error)

View File

@ -51,7 +51,7 @@ namespace osu.Game.Overlays.Settings.Sections
private IDisposable realmSubscription; private IDisposable realmSubscription;
private IQueryable<SkinInfo> realmSkins => private IQueryable<SkinInfo> queryRealmSkins() =>
realmFactory.Context.All<SkinInfo>() realmFactory.Context.All<SkinInfo>()
.Where(s => !s.DeletePending) .Where(s => !s.DeletePending)
.OrderByDescending(s => s.Protected) // protected skins should be at the top. .OrderByDescending(s => s.Protected) // protected skins should be at the top.
@ -83,13 +83,12 @@ namespace osu.Game.Overlays.Settings.Sections
skinDropdown.Current = dropdownBindable; skinDropdown.Current = dropdownBindable;
realmSubscription = realmFactory.Register(realm => realmSkins realmSubscription = realmFactory.Register(realm => queryRealmSkins(), (sender, changes, error) =>
.QueryAsyncWithNotifications((sender, changes, error) =>
{ {
// The first fire of this is a bit redundant due to the call below, // The first fire of this is a bit redundant due to the call below,
// but this is safest in case the subscription is restored after a context recycle. // but this is safest in case the subscription is restored after a context recycle.
updateItems(); updateItems();
})); });
updateItems(); updateItems();
@ -129,9 +128,9 @@ namespace osu.Game.Overlays.Settings.Sections
private void updateItems() private void updateItems()
{ {
int protectedCount = realmSkins.Count(s => s.Protected); int protectedCount = queryRealmSkins().Count(s => s.Protected);
skinItems = realmSkins.ToLive(realmFactory); skinItems = queryRealmSkins().ToLive(realmFactory);
skinItems.Insert(protectedCount, random_skin_info); skinItems.Insert(protectedCount, random_skin_info);

View File

@ -191,12 +191,12 @@ namespace osu.Game.Screens.Select
base.LoadComplete(); base.LoadComplete();
subscriptionSets = realmFactory.Register(getBeatmapSets, beatmapSetsChanged); subscriptionSets = realmFactory.Register(getBeatmapSets, beatmapSetsChanged);
subscriptionBeatmaps = realmFactory.Register(realm => realm.All<BeatmapInfo>().Where(b => !b.Hidden).QueryAsyncWithNotifications(beatmapsChanged)); subscriptionBeatmaps = realmFactory.Register(realm => realm.All<BeatmapInfo>().Where(b => !b.Hidden), 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.
// https://github.com/realm/realm-dotnet/discussions/2634#discussioncomment-1605595. // https://github.com/realm/realm-dotnet/discussions/2634#discussioncomment-1605595.
subscriptionDeletedSets = realmFactory.Register(realm => realm.All<BeatmapSetInfo>().Where(s => s.DeletePending && !s.Protected).QueryAsyncWithNotifications(deletedBeatmapSetsChanged)); subscriptionDeletedSets = realmFactory.Register(realm => realm.All<BeatmapSetInfo>().Where(s => s.DeletePending && !s.Protected), deletedBeatmapSetsChanged);
subscriptionHiddenBeatmaps = realmFactory.Register(realm => realm.All<BeatmapInfo>().Where(b => b.Hidden).QueryAsyncWithNotifications(beatmapsChanged)); subscriptionHiddenBeatmaps = realmFactory.Register(realm => realm.All<BeatmapInfo>().Where(b => b.Hidden), beatmapsChanged);
} }
private void deletedBeatmapSetsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet changes, Exception error) private void deletedBeatmapSetsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet changes, Exception error)

View File

@ -54,13 +54,13 @@ namespace osu.Game.Screens.Select.Carousel
+ $" && {nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} == $1" + $" && {nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} == $1"
+ $" && {nameof(ScoreInfo.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $2" + $" && {nameof(ScoreInfo.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $2"
+ $" && {nameof(ScoreInfo.DeletePending)} == false", api.LocalUser.Value.Id, beatmapInfo.ID, ruleset.Value.ShortName) + $" && {nameof(ScoreInfo.DeletePending)} == false", api.LocalUser.Value.Id, beatmapInfo.ID, ruleset.Value.ShortName)
.OrderByDescending(s => s.TotalScore) .OrderByDescending(s => s.TotalScore),
.QueryAsyncWithNotifications((items, changes, ___) => (items, changes, ___) =>
{ {
Rank = items.FirstOrDefault()?.Rank; Rank = items.FirstOrDefault()?.Rank;
// Required since presence is changed via IsPresent override // Required since presence is changed via IsPresent override
Invalidate(Invalidation.Presence); Invalidate(Invalidation.Presence);
})); });
}, true); }, true);
} }

View File

@ -115,12 +115,12 @@ namespace osu.Game.Screens.Select.Leaderboards
scoreSubscription = realmFactory.Register(realm => scoreSubscription = realmFactory.Register(realm =>
realm.All<ScoreInfo>() realm.All<ScoreInfo>()
.Filter($"{nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} = $0", beatmapInfo.ID) .Filter($"{nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} = $0", beatmapInfo.ID),
.QueryAsyncWithNotifications((_, changes, ___) => (_, changes, ___) =>
{ {
if (!IsOnlineScope) if (!IsOnlineScope)
RefreshScores(); RefreshScores();
})); });
} }
protected override void Reset() protected override void Reset()