Skip to content

Commit

Permalink
Merge pull request #192 from peppy/bypass-attrib-row-insert
Browse files Browse the repository at this point in the history
Allow bypassing attrib row insertion to improve performance
  • Loading branch information
smoogipoo authored Sep 21, 2021
2 parents 717b05b + 6bd30af commit 796fb47
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
6 changes: 6 additions & 0 deletions osu.Server.DifficultyCalculator/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public static class AppSettings
/// </summary>
public static readonly bool INSERT_BEATMAPS;

/// <summary>
/// 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).
/// </summary>
public static readonly bool SKIP_INSERT_ATTRIBUTES;

/// <summary>
/// A full or relative path used to store beatmaps.
/// </summary>
Expand Down Expand Up @@ -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";

Expand Down
35 changes: 19 additions & 16 deletions osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,28 @@ private void computeDifficulty(int beatmapId, WorkingBeatmap beatmap, Ruleset ru
Diff = attribute.StarRating
});

var parameters = new List<object>();

foreach (var mapping in attribute.Map())
if (!AppSettings.SKIP_INSERT_ATTRIBUTES)
{
parameters.Add(new
var parameters = new List<object>();

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))
{
Expand Down

0 comments on commit 796fb47

Please sign in to comment.