From ccddf9b47d94d9f7a3b00aa0e05c577f886e13ae Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 20 Jan 2022 16:49:39 +0900 Subject: [PATCH] Avoid constructor overhead for realm `BeatmapSetInfo` parameterless constructor --- osu.Game/Beatmaps/BeatmapSetInfo.cs | 16 +++++++++++++++- osu.Game/Database/RealmObjectExtensions.cs | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/BeatmapSetInfo.cs b/osu.Game/Beatmaps/BeatmapSetInfo.cs index a934d1a2e3..3cda111e97 100644 --- a/osu.Game/Beatmaps/BeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/BeatmapSetInfo.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using JetBrains.Annotations; using osu.Framework.Testing; using osu.Game.Database; using osu.Game.Extensions; @@ -19,7 +20,7 @@ namespace osu.Game.Beatmaps public class BeatmapSetInfo : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftDelete, IEquatable, IBeatmapSetInfo { [PrimaryKey] - public Guid ID { get; set; } = Guid.NewGuid(); + public Guid ID { get; set; } [Indexed] public int OnlineID { get; set; } = -1; @@ -57,6 +58,19 @@ namespace osu.Game.Beatmaps public double MaxBPM => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.BPM); + public BeatmapSetInfo(IEnumerable? beatmaps = null) + : this() + { + ID = Guid.NewGuid(); + if (beatmaps != null) + Beatmaps.AddRange(beatmaps); + } + + [UsedImplicitly] // Realm + private BeatmapSetInfo() + { + } + /// /// Returns the storage path for the file in this beatmapset with the given filename, if any exists, otherwise null. /// The path returned is relative to the user file storage. diff --git a/osu.Game/Database/RealmObjectExtensions.cs b/osu.Game/Database/RealmObjectExtensions.cs index 746a43fd37..c25aeab336 100644 --- a/osu.Game/Database/RealmObjectExtensions.cs +++ b/osu.Game/Database/RealmObjectExtensions.cs @@ -48,6 +48,7 @@ namespace osu.Game.Database copyChangesToRealm(s.Metadata, d.Metadata); }); c.CreateMap() + .ConstructUsing(_ => new BeatmapSetInfo(null)) .ForMember(s => s.Beatmaps, cc => cc.Ignore()) .AfterMap((s, d) => { @@ -77,6 +78,7 @@ namespace osu.Game.Database applyCommonConfiguration(c); c.CreateMap() + .ConstructUsing(_ => new BeatmapSetInfo(null)) .MaxDepth(2) .AfterMap((s, d) => { @@ -109,6 +111,7 @@ namespace osu.Game.Database applyCommonConfiguration(c); c.CreateMap() + .ConstructUsing(_ => new BeatmapSetInfo(null)) .MaxDepth(2) .ForMember(b => b.Files, cc => cc.Ignore()) .AfterMap((s, d) =>