1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:07:25 +08:00

Update remaining cases of clashes with realm.Write and realm.RegisterForNotifications

This commit is contained in:
Dean Herbert 2022-01-25 13:09:47 +09:00
parent e23b10e6a5
commit d7342880f5
15 changed files with 39 additions and 39 deletions

View File

@ -60,11 +60,11 @@ namespace osu.Game.Tests.Database
KeyBindingContainer testContainer = new TestKeyBindingContainer(); KeyBindingContainer testContainer = new TestKeyBindingContainer();
// Add some excess bindings for an action which only supports 1. // Add some excess bindings for an action which only supports 1.
realm.Write(realm => realm.Write(r =>
{ {
realm.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.A))); r.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.A)));
realm.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.S))); r.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.S)));
realm.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.D))); r.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.D)));
}); });
Assert.That(queryCount(GlobalAction.Back), Is.EqualTo(3)); Assert.That(queryCount(GlobalAction.Back), Is.EqualTo(3));

View File

@ -101,15 +101,15 @@ namespace osu.Game.Database
{ {
using (var ef = efContextFactory.Get()) using (var ef = efContextFactory.Get())
{ {
realm.Write(realm => realm.Write(r =>
{ {
// Before beginning, ensure realm is in an empty state. // Before beginning, ensure realm is in an empty state.
// Migrations which are half-completed could lead to issues if the user tries a second time. // Migrations which are half-completed could lead to issues if the user tries a second time.
// Note that we only do this for beatmaps and scores since the other migrations are yonks old. // Note that we only do this for beatmaps and scores since the other migrations are yonks old.
realm.RemoveAll<BeatmapSetInfo>(); r.RemoveAll<BeatmapSetInfo>();
realm.RemoveAll<BeatmapInfo>(); r.RemoveAll<BeatmapInfo>();
realm.RemoveAll<BeatmapMetadata>(); r.RemoveAll<BeatmapMetadata>();
realm.RemoveAll<ScoreInfo>(); r.RemoveAll<ScoreInfo>();
}); });
migrateSettings(ef); migrateSettings(ef);

View File

@ -55,7 +55,7 @@ namespace osu.Game.Input.Bindings
protected override void LoadComplete() protected override void LoadComplete()
{ {
realmSubscription = realm.RegisterForNotifications(realm => queryRealmKeyBindings(), (sender, changes, error) => realmSubscription = realm.RegisterForNotifications(r => queryRealmKeyBindings(), (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.

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 = realm.RegisterForNotifications(realm => realm.All<BeatmapSetInfo>().Where(s => s.OnlineID == TrackedItem.OnlineID && !s.DeletePending), (items, changes, ___) => realmSubscription = realm.RegisterForNotifications(r => r.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));

View File

@ -78,7 +78,7 @@ 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 = realm.RegisterForNotifications(realm => filteredBeatmaps(), (items, changes, ___) => realmSubscription = realm.RegisterForNotifications(r => filteredBeatmaps(), (items, changes, ___) =>
{ {
if (changes == null) if (changes == null)
return; return;

View File

@ -47,7 +47,7 @@ namespace osu.Game.Online
Downloader.DownloadBegan += downloadBegan; Downloader.DownloadBegan += downloadBegan;
Downloader.DownloadFailed += downloadFailed; Downloader.DownloadFailed += downloadFailed;
realmSubscription = realm.RegisterForNotifications(realm => realm.All<ScoreInfo>().Where(s => ((s.OnlineID > 0 && s.OnlineID == TrackedItem.OnlineID) || s.Hash == TrackedItem.Hash) && !s.DeletePending), (items, changes, ___) => realmSubscription = realm.RegisterForNotifications(r => r.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));

View File

@ -79,7 +79,7 @@ namespace osu.Game.Overlays
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
beatmapSubscription = realm.RegisterForNotifications(realm => queryRealmBeatmapSets(), beatmapsChanged); beatmapSubscription = realm.RegisterForNotifications(r => queryRealmBeatmapSets(), beatmapsChanged);
} }
private void beatmapsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet changes, Exception error) private void beatmapsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet changes, Exception error)

View File

@ -83,7 +83,7 @@ namespace osu.Game.Overlays.Settings.Sections
skinDropdown.Current = dropdownBindable; skinDropdown.Current = dropdownBindable;
realmSubscription = realm.RegisterForNotifications(realm => queryRealmSkins(), (sender, changes, error) => realmSubscription = realm.RegisterForNotifications(r => queryRealmSkins(), (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.

View File

@ -56,11 +56,11 @@ namespace osu.Game.Rulesets.Configuration
pendingWrites.Clear(); pendingWrites.Clear();
} }
realm?.Write(realm => realm?.Write(r =>
{ {
foreach (var c in changed) foreach (var c in changed)
{ {
var setting = realm.All<RealmRulesetSetting>().First(s => s.RulesetName == rulesetName && s.Variant == variant && s.Key == c.ToString()); var setting = r.All<RealmRulesetSetting>().First(s => s.RulesetName == rulesetName && s.Variant == variant && s.Key == c.ToString());
setting.Value = ConfigStore[c].ToString(); setting.Value = ConfigStore[c].ToString();
} }

View File

@ -18,7 +18,7 @@ namespace osu.Game.Rulesets
{ {
public class RulesetStore : IDisposable, IRulesetStore public class RulesetStore : IDisposable, IRulesetStore
{ {
private readonly RealmAccess realm; private readonly RealmAccess realmAccess;
private const string ruleset_library_prefix = @"osu.Game.Rulesets"; private const string ruleset_library_prefix = @"osu.Game.Rulesets";
@ -33,7 +33,7 @@ namespace osu.Game.Rulesets
public RulesetStore(RealmAccess realm, Storage? storage = null) public RulesetStore(RealmAccess realm, Storage? storage = null)
{ {
this.realm = realm; realmAccess = realm;
// On android in release configuration assemblies are loaded from the apk directly into memory. // On android in release configuration assemblies are loaded from the apk directly into memory.
// We cannot read assemblies from cwd, so should check loaded assemblies instead. // We cannot read assemblies from cwd, so should check loaded assemblies instead.
@ -100,7 +100,7 @@ namespace osu.Game.Rulesets
private void addMissingRulesets() private void addMissingRulesets()
{ {
realm.Write(realm => realmAccess.Write(realm =>
{ {
var rulesets = realm.All<RulesetInfo>(); var rulesets = realm.All<RulesetInfo>();

View File

@ -191,12 +191,12 @@ namespace osu.Game.Screens.Select
base.LoadComplete(); base.LoadComplete();
subscriptionSets = realm.RegisterForNotifications(getBeatmapSets, beatmapSetsChanged); subscriptionSets = realm.RegisterForNotifications(getBeatmapSets, beatmapSetsChanged);
subscriptionBeatmaps = realm.RegisterForNotifications(realm => realm.All<BeatmapInfo>().Where(b => !b.Hidden), beatmapsChanged); subscriptionBeatmaps = realm.RegisterForNotifications(r => r.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 = realm.RegisterForNotifications(realm => realm.All<BeatmapSetInfo>().Where(s => s.DeletePending && !s.Protected), deletedBeatmapSetsChanged); subscriptionDeletedSets = realm.RegisterForNotifications(r => r.All<BeatmapSetInfo>().Where(s => s.DeletePending && !s.Protected), deletedBeatmapSetsChanged);
subscriptionHiddenBeatmaps = realm.RegisterForNotifications(realm => realm.All<BeatmapInfo>().Where(b => b.Hidden), beatmapsChanged); subscriptionHiddenBeatmaps = realm.RegisterForNotifications(r => r.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

@ -48,13 +48,13 @@ namespace osu.Game.Screens.Select.Carousel
ruleset.BindValueChanged(_ => ruleset.BindValueChanged(_ =>
{ {
scoreSubscription?.Dispose(); scoreSubscription?.Dispose();
scoreSubscription = realm.RegisterForNotifications(realm => scoreSubscription = realm.RegisterForNotifications(r =>
realm.All<ScoreInfo>() r.All<ScoreInfo>()
.Filter($"{nameof(ScoreInfo.User)}.{nameof(RealmUser.OnlineID)} == $0" .Filter($"{nameof(ScoreInfo.User)}.{nameof(RealmUser.OnlineID)} == $0"
+ $" && {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),
(items, changes, ___) => (items, changes, ___) =>
{ {
Rank = items.FirstOrDefault()?.Rank; Rank = items.FirstOrDefault()?.Rank;

View File

@ -113,9 +113,9 @@ namespace osu.Game.Screens.Select.Leaderboards
if (beatmapInfo == null) if (beatmapInfo == null)
return; return;
scoreSubscription = realm.RegisterForNotifications(realm => scoreSubscription = realm.RegisterForNotifications(r =>
realm.All<ScoreInfo>() r.All<ScoreInfo>()
.Filter($"{nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} = $0", beatmapInfo.ID), .Filter($"{nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} = $0", beatmapInfo.ID),
(_, changes, ___) => (_, changes, ___) =>
{ {
if (!IsOnlineScope) if (!IsOnlineScope)

View File

@ -87,12 +87,12 @@ namespace osu.Game.Skinning
}; };
// Ensure the default entries are present. // Ensure the default entries are present.
realm.Write(realm => realm.Write(r =>
{ {
foreach (var skin in defaultSkins) foreach (var skin in defaultSkins)
{ {
if (realm.Find<SkinInfo>(skin.SkinInfo.ID) == null) if (r.Find<SkinInfo>(skin.SkinInfo.ID) == null)
realm.Add(skin.SkinInfo.Value); r.Add(skin.SkinInfo.Value);
} }
}); });

View File

@ -92,10 +92,10 @@ namespace osu.Game.Stores
int removedFiles = 0; int removedFiles = 0;
// can potentially be run asynchronously, although we will need to consider operation order for disk deletion vs realm removal. // can potentially be run asynchronously, although we will need to consider operation order for disk deletion vs realm removal.
realm.Write(realm => realm.Write(r =>
{ {
// TODO: consider using a realm native query to avoid iterating all files (https://github.com/realm/realm-dotnet/issues/2659#issuecomment-927823707) // TODO: consider using a realm native query to avoid iterating all files (https://github.com/realm/realm-dotnet/issues/2659#issuecomment-927823707)
var files = realm.All<RealmFile>().ToList(); var files = r.All<RealmFile>().ToList();
foreach (var file in files) foreach (var file in files)
{ {
@ -108,7 +108,7 @@ namespace osu.Game.Stores
{ {
removedFiles++; removedFiles++;
Storage.Delete(file.GetStoragePath()); Storage.Delete(file.GetStoragePath());
realm.Remove(file); r.Remove(file);
} }
catch (Exception e) catch (Exception e)
{ {