mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 03:07:19 +08:00
Merge pull request #16499 from peppy/realm-integration/faster-migration
Improve performance of migration to realm
This commit is contained in:
commit
aa6466dfa4
@ -2,7 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
@ -52,13 +51,12 @@ namespace osu.Game.Database
|
|||||||
private void migrateBeatmaps(DatabaseWriteUsage ef)
|
private void migrateBeatmaps(DatabaseWriteUsage ef)
|
||||||
{
|
{
|
||||||
// can be removed 20220730.
|
// can be removed 20220730.
|
||||||
List<EFBeatmapSetInfo> existingBeatmapSets = ef.Context.EFBeatmapSetInfo
|
var existingBeatmapSets = ef.Context.EFBeatmapSetInfo
|
||||||
.Include(s => s.Beatmaps).ThenInclude(b => b.RulesetInfo)
|
.Include(s => s.Beatmaps).ThenInclude(b => b.RulesetInfo)
|
||||||
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
|
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
|
||||||
.Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty)
|
.Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty)
|
||||||
.Include(s => s.Files).ThenInclude(f => f.FileInfo)
|
.Include(s => s.Files).ThenInclude(f => f.FileInfo)
|
||||||
.Include(s => s.Metadata)
|
.Include(s => s.Metadata);
|
||||||
.ToList();
|
|
||||||
|
|
||||||
Logger.Log("Beginning beatmaps migration to realm", LoggingTarget.Database);
|
Logger.Log("Beginning beatmaps migration to realm", LoggingTarget.Database);
|
||||||
|
|
||||||
@ -69,9 +67,11 @@ namespace osu.Game.Database
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int count = existingBeatmapSets.Count();
|
||||||
|
|
||||||
using (var realm = realmContextFactory.CreateContext())
|
using (var realm = realmContextFactory.CreateContext())
|
||||||
{
|
{
|
||||||
Logger.Log($"Found {existingBeatmapSets.Count} beatmaps in EF", LoggingTarget.Database);
|
Logger.Log($"Found {count} beatmaps in EF", LoggingTarget.Database);
|
||||||
|
|
||||||
if (!hasTakenBackup)
|
if (!hasTakenBackup)
|
||||||
{
|
{
|
||||||
@ -148,12 +148,9 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
Logger.Log($"Successfully migrated {existingBeatmapSets.Count} beatmaps to realm", LoggingTarget.Database);
|
Logger.Log($"Successfully migrated {count} beatmaps to realm", LoggingTarget.Database);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ef.Context.RemoveRange(existingBeatmapSets);
|
|
||||||
// Intentionally don't clean up the files, so they don't get purged by EF.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,12 +180,11 @@ namespace osu.Game.Database
|
|||||||
private void migrateScores(DatabaseWriteUsage db)
|
private void migrateScores(DatabaseWriteUsage db)
|
||||||
{
|
{
|
||||||
// can be removed 20220730.
|
// can be removed 20220730.
|
||||||
List<EFScoreInfo> existingScores = db.Context.ScoreInfo
|
var existingScores = db.Context.ScoreInfo
|
||||||
.Include(s => s.Ruleset)
|
.Include(s => s.Ruleset)
|
||||||
.Include(s => s.BeatmapInfo)
|
.Include(s => s.BeatmapInfo)
|
||||||
.Include(s => s.Files)
|
.Include(s => s.Files)
|
||||||
.ThenInclude(f => f.FileInfo)
|
.ThenInclude(f => f.FileInfo);
|
||||||
.ToList();
|
|
||||||
|
|
||||||
Logger.Log("Beginning scores migration to realm", LoggingTarget.Database);
|
Logger.Log("Beginning scores migration to realm", LoggingTarget.Database);
|
||||||
|
|
||||||
@ -199,9 +195,11 @@ namespace osu.Game.Database
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int count = existingScores.Count();
|
||||||
|
|
||||||
using (var realm = realmContextFactory.CreateContext())
|
using (var realm = realmContextFactory.CreateContext())
|
||||||
{
|
{
|
||||||
Logger.Log($"Found {existingScores.Count} scores in EF", LoggingTarget.Database);
|
Logger.Log($"Found {count} scores in EF", LoggingTarget.Database);
|
||||||
|
|
||||||
if (!hasTakenBackup)
|
if (!hasTakenBackup)
|
||||||
{
|
{
|
||||||
@ -256,12 +254,9 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
Logger.Log($"Successfully migrated {existingScores.Count} scores to realm", LoggingTarget.Database);
|
Logger.Log($"Successfully migrated {count} scores to realm", LoggingTarget.Database);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Context.RemoveRange(existingScores);
|
|
||||||
// Intentionally don't clean up the files, so they don't get purged by EF.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,9 +315,6 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Context.RemoveRange(existingSkins);
|
|
||||||
// Intentionally don't clean up the files, so they don't get purged by EF.
|
|
||||||
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -379,8 +371,6 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Context.RemoveRange(existingSettings);
|
|
||||||
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user