Fix potential blocking operation on OrderByTotalScoreAsync()

In reality this wouldn't be a long process, but the blocking is really
noticeable if you add a Task.Delay(1000) in GetTotalScoreAsync().
This commit is contained in:
smoogipoo 2021-10-08 14:23:53 +09:00
parent a924b982eb
commit b82ed3f167
1 changed files with 6 additions and 3 deletions

View File

@ -72,9 +72,12 @@ public async Task<ScoreInfo[]> OrderByTotalScoreAsync(ScoreInfo[] scores, Cancel
}
}
// 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)
var totalScores = await Task.WhenAll(scores.Select(s => GetTotalScoreAsync(s, cancellationToken: cancellationToken))).ConfigureAwait(false);
return scores.Select((s, i) => (index: i, score: s))
.OrderByDescending(key => totalScores[key.index])
.ThenBy(key => key.score.OnlineScoreID)
.Select(key => key.score)
.ToArray();
}