mirror of
https://github.com/osukey/osukey.git
synced 2025-05-26 07:57:32 +09:00
Move database backup creation to async thread where possible
This commit is contained in:
parent
17dbb599d1
commit
4526f8c07d
@ -123,8 +123,18 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
private void beginMigration()
|
private void beginMigration()
|
||||||
{
|
{
|
||||||
|
const string backup_folder = "backups";
|
||||||
|
|
||||||
|
string backupSuffix = $"before_final_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
||||||
|
|
||||||
|
// required for initial backup.
|
||||||
|
var realmBlockOperations = realm.BlockAllOperations();
|
||||||
|
|
||||||
Task.Factory.StartNew(() =>
|
Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
|
realm.CreateBackup(Path.Combine(backup_folder, $"client.{backupSuffix}.realm"), realmBlockOperations);
|
||||||
|
efContextFactory.CreateBackup(Path.Combine(backup_folder, $"client.{backupSuffix}.db"));
|
||||||
|
|
||||||
using (var ef = efContextFactory.Get())
|
using (var ef = efContextFactory.Get())
|
||||||
{
|
{
|
||||||
realm.Write(r =>
|
realm.Write(r =>
|
||||||
@ -182,7 +192,6 @@ namespace osu.Game.Database
|
|||||||
true);
|
true);
|
||||||
|
|
||||||
const string attachment_filename = "attach_me.zip";
|
const string attachment_filename = "attach_me.zip";
|
||||||
const string backup_folder = "backups";
|
|
||||||
|
|
||||||
var backupStorage = storage.GetStorageForDirectory(backup_folder);
|
var backupStorage = storage.GetStorageForDirectory(backup_folder);
|
||||||
|
|
||||||
@ -209,6 +218,8 @@ namespace osu.Game.Database
|
|||||||
// If we were to not do this, the migration would run another time the next time the user starts the game.
|
// If we were to not do this, the migration would run another time the next time the user starts the game.
|
||||||
deletePreRealmData();
|
deletePreRealmData();
|
||||||
|
|
||||||
|
realmBlockOperations.Dispose();
|
||||||
|
|
||||||
migrationCompleted.SetResult(true);
|
migrationCompleted.SetResult(true);
|
||||||
efContextFactory.SetMigrationCompletion();
|
efContextFactory.SetMigrationCompletion();
|
||||||
});
|
});
|
||||||
|
@ -750,9 +750,9 @@ namespace osu.Game.Database
|
|||||||
private string? getRulesetShortNameFromLegacyID(long rulesetId) =>
|
private string? getRulesetShortNameFromLegacyID(long rulesetId) =>
|
||||||
efContextFactory?.Get().RulesetInfo.FirstOrDefault(r => r.ID == rulesetId)?.ShortName;
|
efContextFactory?.Get().RulesetInfo.FirstOrDefault(r => r.ID == rulesetId)?.ShortName;
|
||||||
|
|
||||||
public void CreateBackup(string backupFilename)
|
public void CreateBackup(string backupFilename, IDisposable? blockAllOperations = null)
|
||||||
{
|
{
|
||||||
using (BlockAllOperations())
|
using (blockAllOperations ?? BlockAllOperations())
|
||||||
{
|
{
|
||||||
Logger.Log($"Creating full realm database backup at {backupFilename}", LoggingTarget.Database);
|
Logger.Log($"Creating full realm database backup at {backupFilename}", LoggingTarget.Database);
|
||||||
|
|
||||||
|
@ -233,19 +233,6 @@ namespace osu.Game
|
|||||||
|
|
||||||
Decoder.RegisterDependencies(RulesetStore);
|
Decoder.RegisterDependencies(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)
|
|
||||||
{
|
|
||||||
const string backup_folder = "backups";
|
|
||||||
|
|
||||||
string migration = $"before_final_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
|
||||||
|
|
||||||
EFContextFactory.CreateBackup(Path.Combine(backup_folder, $"client.{migration}.db"));
|
|
||||||
realm.CreateBackup(Path.Combine(backup_folder, $"client.{migration}.realm"));
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies.CacheAs(Storage);
|
dependencies.CacheAs(Storage);
|
||||||
|
|
||||||
var largeStore = new LargeTextureStore(Host.CreateTextureLoaderStore(new NamespacedResourceStore<byte[]>(Resources, @"Textures")));
|
var largeStore = new LargeTextureStore(Host.CreateTextureLoaderStore(new NamespacedResourceStore<byte[]>(Resources, @"Textures")));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user