mirror of
https://github.com/osukey/osukey.git
synced 2025-05-12 17:17:31 +09:00
Merge pull request #22003 from peppy/fix-leaderboard-fetch-wrong
Fix song select leaderboard potentially showing wrong scores on quick beatmap changes
This commit is contained in:
commit
b34ffb4e9c
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
@ -11,10 +9,11 @@ using osu.Game.Online.API.Requests.Responses;
|
|||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace osu.Game.Online.API.Requests
|
namespace osu.Game.Online.API.Requests
|
||||||
{
|
{
|
||||||
public class GetScoresRequest : APIRequest<APIScoresCollection>
|
public class GetScoresRequest : APIRequest<APIScoresCollection>, IEquatable<GetScoresRequest>
|
||||||
{
|
{
|
||||||
public const int MAX_SCORES_PER_REQUEST = 50;
|
public const int MAX_SCORES_PER_REQUEST = 50;
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ namespace osu.Game.Online.API.Requests
|
|||||||
private readonly IRulesetInfo ruleset;
|
private readonly IRulesetInfo ruleset;
|
||||||
private readonly IEnumerable<IMod> mods;
|
private readonly IEnumerable<IMod> mods;
|
||||||
|
|
||||||
public GetScoresRequest(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset, BeatmapLeaderboardScope scope = BeatmapLeaderboardScope.Global, IEnumerable<IMod> mods = null)
|
public GetScoresRequest(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset, BeatmapLeaderboardScope scope = BeatmapLeaderboardScope.Global, IEnumerable<IMod>? mods = null)
|
||||||
{
|
{
|
||||||
if (beatmapInfo.OnlineID <= 0)
|
if (beatmapInfo.OnlineID <= 0)
|
||||||
throw new InvalidOperationException($"Cannot lookup a beatmap's scores without having a populated {nameof(IBeatmapInfo.OnlineID)}.");
|
throw new InvalidOperationException($"Cannot lookup a beatmap's scores without having a populated {nameof(IBeatmapInfo.OnlineID)}.");
|
||||||
@ -51,5 +50,16 @@ namespace osu.Game.Online.API.Requests
|
|||||||
|
|
||||||
return query.ToString();
|
return query.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Equals(GetScoresRequest? other)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, other)) return false;
|
||||||
|
if (ReferenceEquals(this, other)) return true;
|
||||||
|
|
||||||
|
return beatmapInfo.Equals(other.beatmapInfo)
|
||||||
|
&& scope == other.scope
|
||||||
|
&& ruleset.Equals(other.ruleset)
|
||||||
|
&& mods.SequenceEqual(other.mods);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,14 +152,23 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
else if (filterMods)
|
else if (filterMods)
|
||||||
requestMods = mods.Value;
|
requestMods = mods.Value;
|
||||||
|
|
||||||
scoreRetrievalRequest = new GetScoresRequest(fetchBeatmapInfo, fetchRuleset, Scope, requestMods);
|
scoreRetrievalRequest?.Cancel();
|
||||||
|
|
||||||
scoreRetrievalRequest.Success += response => SetScores(
|
var newRequest = new GetScoresRequest(fetchBeatmapInfo, fetchRuleset, Scope, requestMods);
|
||||||
|
newRequest.Success += response => Schedule(() =>
|
||||||
|
{
|
||||||
|
// Request may have changed since fetch request.
|
||||||
|
// Can't rely on request cancellation due to Schedule inside SetScores so let's play it safe.
|
||||||
|
if (!newRequest.Equals(scoreRetrievalRequest))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SetScores(
|
||||||
scoreManager.OrderByTotalScore(response.Scores.Select(s => s.ToScoreInfo(rulesets, fetchBeatmapInfo))),
|
scoreManager.OrderByTotalScore(response.Scores.Select(s => s.ToScoreInfo(rulesets, fetchBeatmapInfo))),
|
||||||
response.UserScore?.CreateScoreInfo(rulesets, fetchBeatmapInfo)
|
response.UserScore?.CreateScoreInfo(rulesets, fetchBeatmapInfo)
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return scoreRetrievalRequest;
|
return scoreRetrievalRequest = newRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index) => new LeaderboardScore(model, index, IsOnlineScope)
|
protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index) => new LeaderboardScore(model, index, IsOnlineScope)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user