diff --git a/osu.Server.Queues.ScoreStatisticsProcessor/Stores/BeatmapStore.cs b/osu.Server.Queues.ScoreStatisticsProcessor/Stores/BeatmapStore.cs index 03b9a9fe..6a4a758d 100644 --- a/osu.Server.Queues.ScoreStatisticsProcessor/Stores/BeatmapStore.cs +++ b/osu.Server.Queues.ScoreStatisticsProcessor/Stores/BeatmapStore.cs @@ -126,44 +126,37 @@ public async Task GetDifficultyAttributesAsync(Beatmap bea return calculator.Calculate(mods); } - LegacyMods legacyModValue = getLegacyModsForAttributeLookup(beatmap, ruleset, mods); + DifficultyAttributeKey key = new DifficultyAttributeKey(beatmap.beatmap_id, (uint)ruleset.RulesetInfo.OnlineID, (uint)getLegacyModsForAttributeLookup(beatmap, ruleset, mods)); - DifficultyAttributeKey key = new DifficultyAttributeKey(beatmap.beatmap_id, (uint)ruleset.RulesetInfo.OnlineID, (uint)legacyModValue); + return (await attributeMemoryCache.GetOrCreateAsync(key, async cacheEntry => + { + try + { + BeatmapDifficultyAttribute[] dbAttributes = (await connection.QueryAsync( + "SELECT * FROM osu_beatmap_difficulty_attribs WHERE `beatmap_id` = @BeatmapId AND `mode` = @RulesetId AND `mods` = @ModValue", new + { + key.BeatmapId, + key.RulesetId, + key.ModValue + }, transaction: transaction)).ToArray(); + + // approximated + cacheEntry.SetSize(difficulty_attribute_size + beatmap_difficulty_attribute_size * dbAttributes.Length); + cacheEntry.SetSlidingExpiration(memory_cache_sliding_expiration); - return (await attributeMemoryCache.GetOrCreateAsync( - key, - async cacheEntry => + DifficultyAttributes attributes = LegacyRulesetHelper.CreateDifficultyAttributes(ruleset.RulesetInfo.OnlineID); + attributes.FromDatabaseAttributes(dbAttributes.ToDictionary(a => (int)a.attrib_id, a => (double)a.value), beatmap); + return attributes; + } + catch (Exception ex) { - try - { - DifficultyAttributes attribs = LegacyRulesetHelper.CreateDifficultyAttributes(ruleset.RulesetInfo.OnlineID); - - BeatmapDifficultyAttribute[] dbAttribs = (await connection.QueryAsync( - "SELECT * FROM osu_beatmap_difficulty_attribs WHERE `beatmap_id` = @BeatmapId AND `mode` = @RulesetId AND `mods` = @ModValue", new - { - key.BeatmapId, - key.RulesetId, - key.ModValue - }, transaction: transaction)).ToArray(); - - attribs.FromDatabaseAttributes(dbAttribs.ToDictionary(a => (int)a.attrib_id, a => (double)a.value), beatmap); - - cacheEntry.SetSlidingExpiration(memory_cache_sliding_expiration); - - // approximated - cacheEntry.SetSize(difficulty_attribute_size + beatmap_difficulty_attribute_size * dbAttribs.Length); - - return attribs; - } - catch (Exception ex) - { - throw new DifficultyAttributesMissingException(key, ex); - } - finally - { - Interlocked.Increment(ref attribCacheMiss); - } - }))!; + throw new DifficultyAttributesMissingException(key, ex); + } + finally + { + Interlocked.Increment(ref attribCacheMiss); + } + }))!; } /// @@ -191,23 +184,20 @@ private static LegacyMods getLegacyModsForAttributeLookup(Beatmap beatmap, Rules /// The . /// An existing transaction. /// The retrieved beatmap, or null if not existing. - public Task GetBeatmapAsync(uint beatmapId, MySqlConnection connection, MySqlTransaction? transaction = null) - { - return beatmapMemoryCache.GetOrCreateAsync( - beatmapId, - cacheEntry => - { - Interlocked.Increment(ref beatmapCacheMiss); + public Task GetBeatmapAsync(uint beatmapId, MySqlConnection connection, MySqlTransaction? transaction = null) => beatmapMemoryCache.GetOrCreateAsync( + beatmapId, + cacheEntry => + { + Interlocked.Increment(ref beatmapCacheMiss); - cacheEntry.SetSlidingExpiration(memory_cache_sliding_expiration); - cacheEntry.SetSize(beatmap_size); + cacheEntry.SetSlidingExpiration(memory_cache_sliding_expiration); + cacheEntry.SetSize(beatmap_size); - return connection.QuerySingleOrDefaultAsync("SELECT * FROM osu_beatmaps WHERE `beatmap_id` = @BeatmapId", new - { - BeatmapId = beatmapId - }, transaction: transaction); - }); - } + return connection.QuerySingleOrDefaultAsync("SELECT * FROM osu_beatmaps WHERE `beatmap_id` = @BeatmapId", new + { + BeatmapId = beatmapId + }, transaction: transaction); + }); /// /// Whether performance points may be awarded for the given beatmap and ruleset combination.