Fix various failures in initial statistics fetch

- If the local user is restricted, then attempting to fetch their data
  from the `/users` endpoint would result in an empty response.

- Even if the user was successfully fetched, their `RulesetsStatistics`
  may not be populated (and instead be `null`). Curiously this was not
  picked up by static analysis until the first issue was fixed.

Closes #21839.
This commit is contained in:
Bartłomiej Dach 2022-12-28 07:28:18 +01:00
parent 5e8ca11ded
commit e9d32fca18
No known key found for this signature in database

View File

@ -75,15 +75,27 @@ namespace osu.Game.Online.Solo
return;
var userRequest = new GetUsersRequest(new[] { localUser.OnlineID });
userRequest.Success += response => Schedule(() =>
{
latestStatistics = new Dictionary<string, UserStatistics>();
foreach (var rulesetStats in response.Users.Single().RulesetsStatistics)
latestStatistics.Add(rulesetStats.Key, rulesetStats.Value);
});
userRequest.Success += initialiseUserStatistics;
api.Queue(userRequest);
});
private void initialiseUserStatistics(GetUsersResponse response) => Schedule(() =>
{
var user = response.Users.SingleOrDefault();
// possible if the user is restricted or similar.
if (user == null)
return;
latestStatistics = new Dictionary<string, UserStatistics>();
if (user.RulesetsStatistics != null)
{
foreach (var rulesetStats in user.RulesetsStatistics)
latestStatistics.Add(rulesetStats.Key, rulesetStats.Value);
}
});
private void userScoreProcessed(int userId, long scoreId)
{
if (userId != api.LocalUser.Value?.OnlineID)