mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 20:13:21 +08:00
Simplify nesting of OrderByTotalScoreAsync
This commit is contained in:
parent
92f59c10f5
commit
3d8faea4b0
@ -116,25 +116,20 @@ namespace osu.Game.Scoring
|
||||
{
|
||||
var difficultyCache = difficulties?.Invoke();
|
||||
|
||||
if (difficultyCache == null)
|
||||
return orderByTotalScore(scores);
|
||||
|
||||
// Compute difficulties asynchronously first to prevent blocking via the GetTotalScore() call below.
|
||||
foreach (var s in scores)
|
||||
if (difficultyCache != null)
|
||||
{
|
||||
await difficultyCache.GetDifficultyAsync(s.Beatmap, s.Ruleset, s.Mods, cancellationToken).ConfigureAwait(false);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
// Compute difficulties asynchronously first to prevent blocking via the GetTotalScore() call below.
|
||||
foreach (var s in scores)
|
||||
{
|
||||
await difficultyCache.GetDifficultyAsync(s.Beatmap, s.Ruleset, s.Mods, cancellationToken).ConfigureAwait(false);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
}
|
||||
|
||||
return orderByTotalScore(scores);
|
||||
|
||||
ScoreInfo[] orderByTotalScore(IEnumerable<ScoreInfo> incoming)
|
||||
{
|
||||
// We're calling .Result, but this should not be a blocking call due to the above GetDifficultyAsync() calls.
|
||||
return incoming.OrderByDescending(s => GetTotalScoreAsync(s, cancellationToken: cancellationToken).Result)
|
||||
.ThenBy(s => s.OnlineScoreID)
|
||||
.ToArray();
|
||||
}
|
||||
// We're calling .Result, but this should not be a blocking call due to the above GetDifficultyAsync() calls.
|
||||
return scores.OrderByDescending(s => GetTotalScoreAsync(s, cancellationToken: cancellationToken).Result)
|
||||
.ThenBy(s => s.OnlineScoreID)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user