From dcfe9c67e3019f91e5b92f1e433dae48d4c79843 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 15 Sep 2021 17:01:31 +0900 Subject: [PATCH] Make ruleset id non-nullable --- osu.Game/Configuration/RealmRulesetSetting.cs | 3 ++- osu.Game/OsuGameBase.cs | 4 +++- .../Configuration/RulesetConfigManager.cs | 15 +++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/osu.Game/Configuration/RealmRulesetSetting.cs b/osu.Game/Configuration/RealmRulesetSetting.cs index 7623d1f948..c88a261ad2 100644 --- a/osu.Game/Configuration/RealmRulesetSetting.cs +++ b/osu.Game/Configuration/RealmRulesetSetting.cs @@ -13,7 +13,8 @@ public class RealmRulesetSetting : RealmObject, IHasGuidPrimaryKey [PrimaryKey] public Guid ID { get; set; } = Guid.NewGuid(); - public int? RulesetID { get; set; } + [Indexed] + public int RulesetID { get; set; } public int? Variant { get; set; } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 4e4061db9d..36406ded08 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -458,11 +458,13 @@ private void migrateDataToRealm() { foreach (var dkb in existingSettings) { + if (dkb.RulesetID == null) continue; + usage.Realm.Add(new RealmRulesetSetting { ValueString = dkb.StringValue, Key = dkb.Key, - RulesetID = dkb.RulesetID, + RulesetID = dkb.RulesetID.Value, Variant = dkb.Variant }); } diff --git a/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs b/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs index 3f5472e52c..a97976392a 100644 --- a/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs +++ b/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs @@ -20,12 +20,17 @@ public abstract class RulesetConfigManager : ConfigManager, IR private List databasedSettings = new List(); - private readonly RulesetInfo ruleset; + private readonly int rulesetId; protected RulesetConfigManager(SettingsStore store, RulesetInfo ruleset, int? variant = null) { realmFactory = store?.Realm; - this.ruleset = ruleset; + + if (realmFactory != null && !ruleset.ID.HasValue) + throw new InvalidOperationException("Attempted to add databased settings for a non-databased ruleset"); + + rulesetId = ruleset.ID ?? -1; + this.variant = variant; Load(); @@ -35,12 +40,10 @@ protected RulesetConfigManager(SettingsStore store, RulesetInfo ruleset, int? va protected override void PerformLoad() { - var rulesetID = ruleset?.ID; - if (realmFactory != null) { // As long as RulesetConfigCache exists, there is no need to subscribe to realm events. - databasedSettings = realmFactory.Context.All().Where(b => b.RulesetID == rulesetID && b.Variant == variant).ToList(); + databasedSettings = realmFactory.Context.All().Where(b => b.RulesetID == rulesetId && b.Variant == variant).ToList(); } } @@ -66,7 +69,7 @@ protected override void AddBindable(TLookup lookup, Bindable