From 505fede44d93ff68c5ad150d1641b25143bef701 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 23 Nov 2021 16:27:28 +0900 Subject: [PATCH] Pass the full EF context rather than a legacy `RulesetStore` --- osu.Game/Database/RealmContextFactory.cs | 18 +++++++++++++----- osu.Game/OsuGameBase.cs | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/osu.Game/Database/RealmContextFactory.cs b/osu.Game/Database/RealmContextFactory.cs index 70ea24b581..f04492d0e8 100644 --- a/osu.Game/Database/RealmContextFactory.cs +++ b/osu.Game/Database/RealmContextFactory.cs @@ -14,7 +14,6 @@ using osu.Framework.Statistics; using osu.Game.Configuration; using osu.Game.Input.Bindings; using osu.Game.Models; -using osu.Game.Rulesets; using Realms; #nullable enable @@ -33,7 +32,7 @@ namespace osu.Game.Database /// public readonly string Filename; - private readonly RulesetStore? rulesets; + private readonly IDatabaseContextFactory? efContextFactory; /// /// Version history: @@ -77,10 +76,10 @@ namespace osu.Game.Database } } - public RealmContextFactory(Storage storage, string filename, RulesetStore? rulesets = null) + public RealmContextFactory(Storage storage, string filename, IDatabaseContextFactory? efContextFactory = null) { this.storage = storage; - this.rulesets = rulesets; + this.efContextFactory = efContextFactory; Filename = filename; @@ -252,7 +251,7 @@ namespace osu.Game.Database var newItem = newSettings.ElementAt(i); long rulesetId = oldItem.RulesetID; - string? rulesetName = rulesets?.GetRuleset((int)rulesetId)?.ShortName; + string? rulesetName = getRulesetShortNameFromLegacyID(rulesetId); if (string.IsNullOrEmpty(rulesetName)) migration.NewRealm.Remove(newItem); @@ -264,6 +263,15 @@ namespace osu.Game.Database } } + private string? getRulesetShortNameFromLegacyID(long rulesetId) + { + if (efContextFactory == null) + return null; + + using (var efContext = efContextFactory.Get()) + return efContext.RulesetInfo.First(r => r.ID == rulesetId)?.ShortName; + } + /// /// Flush any active contexts and block any further writes. /// diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index a2dd417491..1890fd7d24 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -192,7 +192,7 @@ namespace osu.Game dependencies.Cache(RulesetStore = new RulesetStore(contextFactory, Storage)); - dependencies.Cache(realmFactory = new RealmContextFactory(Storage, "client", RulesetStore)); + dependencies.Cache(realmFactory = new RealmContextFactory(Storage, "client", contextFactory)); dependencies.CacheAs(Storage);