From e3a230320ae1aa3b1f2279b539d0e97b416d48fc Mon Sep 17 00:00:00 2001
From: Aergwyn <aergwyn@t-online.de>
Date: Thu, 23 Nov 2017 19:46:58 +0100
Subject: [PATCH] compare metdata and remove duplicate from beatmap to prevent
 redundant storage

---
 osu.Game/Beatmaps/BeatmapManager.cs  |  4 ++++
 osu.Game/Beatmaps/BeatmapMetadata.cs | 18 ++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs
index eb10b23c6f..ca715b8d1e 100644
--- a/osu.Game/Beatmaps/BeatmapManager.cs
+++ b/osu.Game/Beatmaps/BeatmapManager.cs
@@ -515,6 +515,10 @@ namespace osu.Game.Beatmaps
 
                     if (existing == null)
                     {
+                        // Exclude beatmap-metadata if it's equal to beatmapset-metadata
+                        if (metadata.Equals(beatmap.Metadata))
+                            beatmap.BeatmapInfo.Metadata = null;
+
                         RulesetInfo ruleset = rulesets.GetRuleset(beatmap.BeatmapInfo.RulesetID);
 
                         // TODO: this should be done in a better place once we actually need to dynamically update it.
diff --git a/osu.Game/Beatmaps/BeatmapMetadata.cs b/osu.Game/Beatmaps/BeatmapMetadata.cs
index 89f9ebf47a..2cd8e2669f 100644
--- a/osu.Game/Beatmaps/BeatmapMetadata.cs
+++ b/osu.Game/Beatmaps/BeatmapMetadata.cs
@@ -66,5 +66,23 @@ namespace osu.Game.Beatmaps
             Source,
             Tags
         }.Where(s => !string.IsNullOrEmpty(s)).ToArray();
+
+        public override bool Equals(object other)
+        {
+            var otherMetadata = other as BeatmapMetadata;
+            if (otherMetadata == null) return false;
+
+            return (onlineBeatmapSetID?.Equals(otherMetadata.onlineBeatmapSetID) ?? false)
+                && (Title?.Equals(otherMetadata.Title) ?? false)
+                && (TitleUnicode?.Equals(otherMetadata.TitleUnicode) ?? false)
+                && (Artist?.Equals(otherMetadata.Artist) ?? false)
+                && (ArtistUnicode?.Equals(otherMetadata.ArtistUnicode) ?? false)
+                && (AuthorString?.Equals(otherMetadata.AuthorString) ?? false)
+                && (Source?.Equals(otherMetadata.Source) ?? false)
+                && (Tags?.Equals(otherMetadata.Tags) ?? false)
+                && PreviewTime.Equals(otherMetadata.PreviewTime)
+                && (AudioFile?.Equals(otherMetadata.AudioFile) ?? false)
+                && (BackgroundFile?.Equals(otherMetadata.BackgroundFile) ?? false);
+        }
     }
 }