mirror of
https://github.com/ppy/osu.git
synced 2025-02-12 11:52:57 +08:00
Create backup before any realm contexts are used
This commit is contained in:
parent
5622d2ba4f
commit
855ef3fa92
@ -100,10 +100,6 @@ namespace osu.Game.Database
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
// needs to be run on the update thread because of realm BlockAllOperations.
|
||||
// maybe we can work around this? not sure..
|
||||
createBackup();
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
using (var ef = efContextFactory.Get())
|
||||
@ -470,17 +466,5 @@ namespace osu.Game.Database
|
||||
|
||||
private string? getRulesetShortNameFromLegacyID(long rulesetId) =>
|
||||
efContextFactory.Get().RulesetInfo.FirstOrDefault(r => r.ID == rulesetId)?.ShortName;
|
||||
|
||||
private void createBackup()
|
||||
{
|
||||
string migration = $"before_final_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
||||
|
||||
efContextFactory.CreateBackup($"client.{migration}.db");
|
||||
realmContextFactory.CreateBackup($"client.{migration}.realm");
|
||||
|
||||
using (var source = storage.GetStream("collection.db"))
|
||||
using (var destination = storage.GetStream($"collection.{migration}.db", FileAccess.Write, FileMode.CreateNew))
|
||||
source.CopyTo(destination);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -197,6 +197,21 @@ namespace osu.Game
|
||||
dependencies.Cache(RulesetStore = new RulesetStore(realmFactory, Storage));
|
||||
dependencies.CacheAs<IRulesetStore>(RulesetStore);
|
||||
|
||||
// Backup is taken here rather than in EFToRealmMigrator to avoid recycling realm contexts
|
||||
// after initial usages below. It can be moved once a direction is established for handling re-subscription.
|
||||
// See https://github.com/ppy/osu/pull/16547 for more discussion.
|
||||
if (EFContextFactory != null)
|
||||
{
|
||||
string migration = $"before_final_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
||||
|
||||
EFContextFactory.CreateBackup($"client.{migration}.db");
|
||||
realmFactory.CreateBackup($"client.{migration}.realm");
|
||||
|
||||
using (var source = Storage.GetStream("collection.db"))
|
||||
using (var destination = Storage.GetStream($"collection.{migration}.db", FileAccess.Write, FileMode.CreateNew))
|
||||
source.CopyTo(destination);
|
||||
}
|
||||
|
||||
dependencies.CacheAs(Storage);
|
||||
|
||||
var largeStore = new LargeTextureStore(Host.CreateTextureLoaderStore(new NamespacedResourceStore<byte[]>(Resources, @"Textures")));
|
||||
|
Loading…
Reference in New Issue
Block a user