mirror of https://github.com/ppy/osu
Make ruleset id non-nullable
This commit is contained in:
parent
80ecf81be3
commit
dcfe9c67e3
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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
|
||||
});
|
||||
}
|
||||
|
|
|
@ -20,12 +20,17 @@ public abstract class RulesetConfigManager<TLookup> : ConfigManager<TLookup>, IR
|
|||
|
||||
private List<RealmRulesetSetting> databasedSettings = new List<RealmRulesetSetting>();
|
||||
|
||||
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<RealmRulesetSetting>().Where(b => b.RulesetID == rulesetID && b.Variant == variant).ToList();
|
||||
databasedSettings = realmFactory.Context.All<RealmRulesetSetting>().Where(b => b.RulesetID == rulesetId && b.Variant == variant).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +69,7 @@ protected override void AddBindable<TBindable>(TLookup lookup, Bindable<TBindabl
|
|||
{
|
||||
Key = lookup.ToString(),
|
||||
Value = bindable.Value,
|
||||
RulesetID = ruleset?.ID,
|
||||
RulesetID = rulesetId,
|
||||
Variant = variant,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue