Factor in total score calculation time in results screen load

This commit is contained in:
smoogipoo 2021-09-07 15:18:59 +09:00
parent c9325cc419
commit 4658577b1d
2 changed files with 26 additions and 20 deletions

View File

@ -32,6 +32,9 @@ public class PlaylistsResultsScreen : ResultsScreen
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
[Resolved]
private ScoreManager scoreManager { get; set; }
public PlaylistsResultsScreen(ScoreInfo score, long roomId, PlaylistItem playlistItem, bool allowRetry, bool allowWatchingReplay = true) public PlaylistsResultsScreen(ScoreInfo score, long roomId, PlaylistItem playlistItem, bool allowRetry, bool allowWatchingReplay = true)
: base(score, allowRetry, allowWatchingReplay) : base(score, allowRetry, allowWatchingReplay)
{ {
@ -166,23 +169,28 @@ private APIRequest createIndexRequest(Action<IEnumerable<ScoreInfo>> scoresCallb
/// <param name="pivot">An optional pivot around which the scores were retrieved.</param> /// <param name="pivot">An optional pivot around which the scores were retrieved.</param>
private void performSuccessCallback([NotNull] Action<IEnumerable<ScoreInfo>> callback, [NotNull] List<MultiplayerScore> scores, [CanBeNull] MultiplayerScores pivot = null) private void performSuccessCallback([NotNull] Action<IEnumerable<ScoreInfo>> callback, [NotNull] List<MultiplayerScore> scores, [CanBeNull] MultiplayerScores pivot = null)
{ {
var scoreInfos = new List<ScoreInfo>(scores.Select(s => s.CreateScoreInfo(playlistItem))); var scoreInfos = scores.Select(s => s.CreateScoreInfo(playlistItem)).ToArray();
// Select a score if we don't already have one selected. // Score panels calculate total score before displaying, which can take some time. In order to count that calculation as part of the loading spinner display duration,
// Note: This is done before the callback so that the panel list centres on the selected score before panels are added (eliminating initial scroll). // calculate the total scores locally before invoking the success callback.
if (SelectedScore.Value == null) scoreManager.OrderByTotalScoreAsync(scoreInfos).ContinueWith(_ => Schedule(() =>
{ {
Schedule(() => // Select a score if we don't already have one selected.
// Note: This is done before the callback so that the panel list centres on the selected score before panels are added (eliminating initial scroll).
if (SelectedScore.Value == null)
{ {
// Prefer selecting the local user's score, or otherwise default to the first visible score. Schedule(() =>
SelectedScore.Value = scoreInfos.FirstOrDefault(s => s.User.Id == api.LocalUser.Value.Id) ?? scoreInfos.FirstOrDefault(); {
}); // Prefer selecting the local user's score, or otherwise default to the first visible score.
} SelectedScore.Value = scoreInfos.FirstOrDefault(s => s.User.Id == api.LocalUser.Value.Id) ?? scoreInfos.FirstOrDefault();
});
}
// Invoke callback to add the scores. Exclude the user's current score which was added previously. // Invoke callback to add the scores. Exclude the user's current score which was added previously.
callback.Invoke(scoreInfos.Where(s => s.OnlineScoreID != Score?.OnlineScoreID)); callback.Invoke(scoreInfos.Where(s => s.OnlineScoreID != Score?.OnlineScoreID));
hideLoadingSpinners(pivot); hideLoadingSpinners(pivot);
}));
} }
private void hideLoadingSpinners([CanBeNull] MultiplayerScores pivot = null) private void hideLoadingSpinners([CanBeNull] MultiplayerScores pivot = null)

View File

@ -52,8 +52,7 @@ public abstract class ResultsScreen : ScreenWithBeatmapBackground, IKeyBindingHa
private Drawable bottomPanel; private Drawable bottomPanel;
private Container<ScorePanel> detachedPanelContainer; private Container<ScorePanel> detachedPanelContainer;
private bool fetchedInitialScores; private bool lastFetchCompleted;
private APIRequest nextPageRequest;
private readonly bool allowRetry; private readonly bool allowRetry;
private readonly bool allowWatchingReplay; private readonly bool allowWatchingReplay;
@ -191,8 +190,10 @@ protected override void Update()
{ {
base.Update(); base.Update();
if (fetchedInitialScores && nextPageRequest == null) if (lastFetchCompleted)
{ {
APIRequest nextPageRequest = null;
if (ScorePanelList.IsScrolledToStart) if (ScorePanelList.IsScrolledToStart)
nextPageRequest = FetchNextPage(-1, fetchScoresCallback); nextPageRequest = FetchNextPage(-1, fetchScoresCallback);
else if (ScorePanelList.IsScrolledToEnd) else if (ScorePanelList.IsScrolledToEnd)
@ -200,10 +201,7 @@ protected override void Update()
if (nextPageRequest != null) if (nextPageRequest != null)
{ {
// Scheduled after children to give the list a chance to update its scroll position and not potentially trigger a second request too early. lastFetchCompleted = false;
nextPageRequest.Success += () => ScheduleAfterChildren(() => nextPageRequest = null);
nextPageRequest.Failure += _ => ScheduleAfterChildren(() => nextPageRequest = null);
api.Queue(nextPageRequest); api.Queue(nextPageRequest);
} }
} }
@ -229,7 +227,7 @@ private void fetchScoresCallback(IEnumerable<ScoreInfo> scores) => Schedule(() =
foreach (var s in scores) foreach (var s in scores)
addScore(s); addScore(s);
fetchedInitialScores = true; lastFetchCompleted = true;
}); });
public override void OnEntering(IScreen last) public override void OnEntering(IScreen last)