Skip to content

Commit 7f6549f

Browse files
committed
Simplify code using ToArray and ToHashSet
The alloc-based performance savings are no longer as large due to the initial beatmap fetch being much more limited.
1 parent 8b29164 commit 7f6549f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

osu.Server.Queues.ScoreStatisticsProcessor/Commands/Maintenance/MarkNonPreservedScoresCommand.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ private async Task processUser(MySqlConnection db, int userId, CancellationToken
8080
return;
8181

8282
if (Verbose) Console.WriteLine("Fetching pins..");
83-
IEnumerable<ulong> pins = db.Query<ulong>("SELECT score_id FROM score_pins WHERE user_id = @userId AND ruleset_id = @rulesetId", parameters);
83+
IEnumerable<ulong> pins = db.Query<ulong>("SELECT score_id FROM score_pins WHERE user_id = @userId AND ruleset_id = @rulesetId", parameters).ToHashSet();
8484
if (Verbose) Console.WriteLine("Fetching multiplayer scores..");
85-
IEnumerable<ulong> multiplayerScores = db.Query<ulong>("SELECT score_id FROM multiplayer_playlist_item_scores WHERE user_id = @userId", parameters);
85+
IEnumerable<ulong> multiplayerScores = db.Query<ulong>("SELECT score_id FROM multiplayer_playlist_item_scores WHERE user_id = @userId", parameters).ToHashSet();
8686

8787
Console.WriteLine($"Processing user {userId} ({scores.Count()} scores)..");
8888

@@ -167,21 +167,21 @@ private static bool checkIsUserHigh(IEnumerable<SoloScore> userScores, SoloScore
167167
s.beatmap_id == candidate.beatmap_id
168168
&& compareMods(candidate, s)
169169
&& s.ranked
170-
);
170+
).ToArray();
171171

172172
// As a special case, if the score we are checking is non-ranked, preserve ranked alternatives but if there are none, compare against non-ranked instead.
173173
if (!candidate.ranked && !scores.Any())
174174
{
175175
scores = userScores.Where(s =>
176176
s.beatmap_id == candidate.beatmap_id
177177
&& compareMods(candidate, s)
178-
);
178+
).ToArray();
179179
}
180180

181181
Debug.Assert(scores.Any());
182182

183183
// shortcut for case of single score match
184-
if (scores.Take(2).Count() == 1)
184+
if (scores.Length == 1)
185185
{
186186
preservedAlternatives = new HashSet<SoloScore> { candidate };
187187
return true;

0 commit comments

Comments
 (0)