From 6bd30af3f3bff87e60ff12f5eada5c53825726fb Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 20 Sep 2021 14:43:06 +0900 Subject: [PATCH] Allow bypassing attrib row insertion to improve performance --- .../AppSettings.cs | 6 ++++ .../ServerDifficultyCalculator.cs | 35 ++++++++++--------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/osu.Server.DifficultyCalculator/AppSettings.cs b/osu.Server.DifficultyCalculator/AppSettings.cs index 1572375..96bc9b8 100644 --- a/osu.Server.DifficultyCalculator/AppSettings.cs +++ b/osu.Server.DifficultyCalculator/AppSettings.cs @@ -12,6 +12,11 @@ public static class AppSettings /// public static readonly bool INSERT_BEATMAPS; + /// + /// Whether to insert entries to `osu_difficulty_attributes`. This is quite an intensive operation, and may be skipped when not required (ie. for sandbox runs). + /// + public static readonly bool SKIP_INSERT_ATTRIBUTES; + /// /// A full or relative path used to store beatmaps. /// @@ -41,6 +46,7 @@ public static class AppSettings static AppSettings() { INSERT_BEATMAPS = Environment.GetEnvironmentVariable("INSERT_BEATMAPS") == "1"; + SKIP_INSERT_ATTRIBUTES = Environment.GetEnvironmentVariable("SKIP_INSERT_ATTRIBUTES") == "1"; ALLOW_DOWNLOAD = Environment.GetEnvironmentVariable("ALLOW_DOWNLOAD") == "1"; SAVE_DOWNLOADED = Environment.GetEnvironmentVariable("SAVE_DOWNLOADED") == "1"; diff --git a/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs b/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs index 7bab3ac..245b32a 100644 --- a/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs +++ b/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs @@ -95,25 +95,28 @@ private void computeDifficulty(int beatmapId, WorkingBeatmap beatmap, Ruleset ru Diff = attribute.StarRating }); - var parameters = new List(); - - foreach (var mapping in attribute.Map()) + if (!AppSettings.SKIP_INSERT_ATTRIBUTES) { - parameters.Add(new + var parameters = new List(); + + foreach (var mapping in attribute.Map()) { - BeatmapId = beatmapId, - Mode = ruleset.RulesetInfo.ID, - Mods = (int)legacyMod, - Attribute = mapping.id, - Value = Convert.ToSingle(mapping.value) - }); - } + parameters.Add(new + { + BeatmapId = beatmapId, + Mode = ruleset.RulesetInfo.ID, + Mods = (int)legacyMod, + Attribute = mapping.id, + Value = Convert.ToSingle(mapping.value) + }); + } - conn?.Execute( - "INSERT INTO `osu_beatmap_difficulty_attribs` (`beatmap_id`, `mode`, `mods`, `attrib_id`, `value`) " - + "VALUES (@BeatmapId, @Mode, @Mods, @Attribute, @Value) " - + "ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)", - parameters.ToArray()); + conn?.Execute( + "INSERT INTO `osu_beatmap_difficulty_attribs` (`beatmap_id`, `mode`, `mods`, `attrib_id`, `value`) " + + "VALUES (@BeatmapId, @Mode, @Mods, @Attribute, @Value) " + + "ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)", + parameters.ToArray()); + } if (legacyMod == LegacyMods.None && ruleset.RulesetInfo.Equals(beatmap.BeatmapInfo.Ruleset)) {