From fd5198d667f256ab59781d686721fd9507256ff7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 19 Jan 2022 16:22:17 +0900 Subject: [PATCH] Avoid using parameterless constructors in migration code Minor performance improvement (less garbage). --- osu.Game/Database/EFToRealmMigrator.cs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/osu.Game/Database/EFToRealmMigrator.cs b/osu.Game/Database/EFToRealmMigrator.cs index a7cfd71ff9..5e49a44733 100644 --- a/osu.Game/Database/EFToRealmMigrator.cs +++ b/osu.Game/Database/EFToRealmMigrator.cs @@ -122,7 +122,10 @@ private void migrateBeatmaps(OsuDbContext ef) foreach (var beatmap in beatmapSet.Beatmaps) { - var realmBeatmap = new BeatmapInfo + var ruleset = realm.Find(beatmap.RulesetInfo.ShortName); + var metadata = getBestMetadata(beatmap.Metadata, beatmapSet.Metadata); + + var realmBeatmap = new BeatmapInfo(ruleset, new BeatmapDifficulty(beatmap.BaseDifficulty), metadata) { DifficultyName = beatmap.DifficultyName, Status = beatmap.Status, @@ -148,9 +151,6 @@ private void migrateBeatmaps(OsuDbContext ef) CountdownOffset = beatmap.CountdownOffset, MaxCombo = beatmap.MaxCombo, Bookmarks = beatmap.Bookmarks, - Ruleset = realm.Find(beatmap.RulesetInfo.ShortName), - Difficulty = new BeatmapDifficulty(beatmap.BaseDifficulty), - Metadata = getBestMetadata(beatmap.Metadata, beatmapSet.Metadata), BeatmapSet = realmBeatmapSet, }; @@ -180,7 +180,7 @@ private BeatmapMetadata getBestMetadata(EFBeatmapMetadata? beatmapMetadata, EFBe TitleUnicode = metadata.TitleUnicode, Artist = metadata.Artist, ArtistUnicode = metadata.ArtistUnicode, - Author = new RealmUser + Author = { OnlineID = metadata.Author.Id, Username = metadata.Author.Username, @@ -248,7 +248,15 @@ private void migrateScores(OsuDbContext db) Logger.Log($"Migrated {written}/{count} scores...", LoggingTarget.Database); } - var realmScore = new ScoreInfo + var beatmap = realm.All().First(b => b.Hash == score.BeatmapInfo.Hash); + var ruleset = realm.Find(score.Ruleset.ShortName); + var user = new RealmUser + { + OnlineID = score.User.OnlineID, + Username = score.User.Username + }; + + var realmScore = new ScoreInfo(beatmap, ruleset, user) { Hash = score.Hash, DeletePending = score.DeletePending, @@ -262,8 +270,8 @@ private void migrateScores(OsuDbContext db) HasReplay = ((IScoreInfo)score).HasReplay, Date = score.Date, PP = score.PP, - BeatmapInfo = realm.All().First(b => b.Hash == score.BeatmapInfo.Hash), - Ruleset = realm.Find(score.Ruleset.ShortName), + BeatmapInfo = beatmap, + Ruleset = ruleset, Rank = score.Rank, HitEvents = score.HitEvents, Passed = score.Passed,