Skip to content

Commit 26f2fc9

Browse files
committed
Fix non-ranked scores not being preserved as expected
1 parent 0249437 commit 26f2fc9

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
67
using System.Linq;
78
using System.Threading;
89
using System.Threading.Tasks;
@@ -102,6 +103,8 @@ private async Task processUser(MySqlConnection db, int userId, CancellationToken
102103
continue;
103104
}
104105

106+
Debug.Assert(preservedAlternatives.Count > 0);
107+
105108
if (Verbose)
106109
{
107110
formatOutput(score, true, "superseded");
@@ -145,25 +148,35 @@ private async Task<bool> checkIsMultiplayerScoreAsync(MySqlConnection db, SoloSc
145148

146149
private static bool checkIsUserHigh(IEnumerable<SoloScore> userScores, SoloScore candidate, out HashSet<SoloScore> preservedAlternatives)
147150
{
148-
userScores = userScores.Where(s =>
151+
var scores = userScores.Where(s =>
149152
s.beatmap_id == candidate.beatmap_id
150153
&& s.ruleset_id == candidate.ruleset_id
151154
&& compareMods(candidate, s)
152155
&& s.ranked
153-
);
156+
).ToArray();
157+
158+
// 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.
159+
if (!candidate.ranked && scores.Length == 0)
160+
{
161+
scores = userScores.Where(s =>
162+
s.beatmap_id == candidate.beatmap_id
163+
&& s.ruleset_id == candidate.ruleset_id
164+
&& compareMods(candidate, s)
165+
).ToArray();
166+
}
154167

155168
preservedAlternatives = new HashSet<SoloScore>();
156169

157170
// TODO: this can likely be optimised (to not recalculate every score, in the case there's many candidates per beatmap).
158-
if (userScores.MaxBy(s => s.pp) is SoloScore maxPPScore)
171+
if (scores.MaxBy(s => s.pp) is SoloScore maxPPScore)
159172
preservedAlternatives.Add(maxPPScore);
160-
if (userScores.Where(s => s.legacy_total_score == 0).MaxBy(s => s.total_score) is SoloScore maxTotalScoreLazer)
173+
if (scores.Where(s => s.legacy_total_score == 0).MaxBy(s => s.total_score) is SoloScore maxTotalScoreLazer)
161174
preservedAlternatives.Add(maxTotalScoreLazer);
162175
// i'm not sure that we need this one but for now let's play it safe and not nuke scores users may care about.
163-
if (userScores.Where(s => s.legacy_total_score > 0).MaxBy(s => s.legacy_total_score) is SoloScore maxTotalScoreStable)
176+
if (scores.Where(s => s.legacy_total_score > 0).MaxBy(s => s.legacy_total_score) is SoloScore maxTotalScoreStable)
164177
preservedAlternatives.Add(maxTotalScoreStable);
165178
// there's a very high possibility that this one is either `maxTotalScoreLazer` or `maxTotalScoreStable`, but just to be 100% sure...
166-
if (userScores.MaxBy(s => s.total_score) is SoloScore maxTotalScore)
179+
if (scores.MaxBy(s => s.total_score) is SoloScore maxTotalScore)
167180
preservedAlternatives.Add(maxTotalScore);
168181

169182
// Check whether this score is the user's highest

0 commit comments

Comments
 (0)