Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle multiple online score ID types #24794

Merged
merged 21 commits into from
Oct 27, 2023

Conversation

bdach
Copy link
Collaborator

@bdach bdach commented Sep 13, 2023

This is going to be hard-stuck on the dependency chain for a while; I'm only PRing it to conclude the chain of changes.

This PR executes the plan outlined in #24229 (comment) for encoding, decoding, and storing online score IDs to realm. This will finally allow stuff like replay download to fully work correctly end-to-end (although an osu-server-spectator bump will be required after this change for the encoder changes to propagate to replays recorded server-side.

While I'm temporarily marking this as draft, most of this is generally tested full-stack to work, with the exception of stable replay handling via online download paths as testing that locally is a pain. Will do more testing (and undraft) once the dependency chain progresses enough for that to be viable.

@bdach
Copy link
Collaborator Author

bdach commented Oct 15, 2023

Just as commentary: while the prerequisites of this pull will likely be obsoleted by ppy/osu-infrastructure#24, the changes in this one should still be valid.

@peppy
Copy link
Member

peppy commented Oct 16, 2023

Just as commentary: while the prerequisites of this pull will likely be obsoleted by ppy/osu-infrastructure#24, the changes in this one should still be valid.

Are you able to split the relevant changes out? I think we're likely definitely going ahead with ppy/osu-infrastructure#24, so may as well clean things up here.

bdach added 8 commits October 16, 2023 11:20
Mostly places that can interact with imported replays.

There are other places that use the online ID as a sort tiebreaker, or
to check presence of a score on results screens, but they should
probably still continue to only use `OnlineID`, since all scores with a
legacy online ID should have an online ID, but the converse is not
generally true.
Previously, for lazer scores, the ID returned from `osu-web` was
discarded and replaced with -1, due to the fact that the appropriate
structures for unification with stable, as well as unification across
solo and multiplayer, were not in place yet.

Now we're at the point where scores from all the aforementioned sources
receive a `solo_scores` DB row, and as such, we can start treating
`solo_scores`-scheme IDs as canonical "online IDs" for a score.
@bdach bdach force-pushed the score-encoding-cleanup branch from c3a4396 to fb22938 Compare October 16, 2023 09:28
@bdach
Copy link
Collaborator Author

bdach commented Oct 16, 2023

Are you able to split the relevant changes out?

I've just force-pushed the dependent commits out. There was zero code overlap and zero conflicts, so the hope is that it will be enough. It doesn't build for now, pending resolution of ppy/osu-infrastructure#24 (comment).

I have not even attempted to test this yet which is why I'm keeping this as draft for the time being. I don't want this PR to go in before work on ppy/osu-infrastructure#24 is completed and verified as working correctly, as otherwise this change may do more damage than good by putting garbage data where it don't belong.

@bdach bdach added the blocked Don't merge this. label Oct 16, 2023
The latter is apparently not going to be a thing anymore.
@peppy
Copy link
Member

peppy commented Oct 26, 2023

@bdach we might be at the point this can be revisited.

@bdach
Copy link
Collaborator Author

bdach commented Oct 26, 2023

I've tested this some and yes, things look to be working pretty well. The only thing I was unable to test is that legacy score imports work correctly, because something seems to be off with private-staging as described on discord.

Taking this out of draft as such.

@bdach bdach marked this pull request as ready for review October 26, 2023 11:27
@bdach bdach removed the blocked Don't merge this. label Oct 26, 2023
@peppy peppy self-requested a review October 26, 2023 12:50
@bdach
Copy link
Collaborator Author

bdach commented Oct 26, 2023

As it turns out (after private-staging was sorted), legacy score import was not working quite correctly just yet. The scenario involved here is something along the lines of:

  1. Import score via stable-recorded replay (via drag-and-drop, or import from stable, or whatever)
  2. The replay should show as downloaded when looking at global leaderboards even if they were fetched from API

They previously wouldn't be, I pushed some commits that should make it so. 526ee6e may be a point of contention here but I think it makes sense? I can split the model jiggling out of this on request.

@peppy
Copy link
Member

peppy commented Oct 27, 2023

I'm looking at the complexity around the replay flags and wondering why we can't switch to this:

diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs
index 6ccf73d8ff..5b32f380b9 100644
--- a/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs
+++ b/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs
@@ -213,7 +213,7 @@ public void CreateButtonWithNoScore()
             OnlineID = hasOnlineId ? online_score_id : 0,
             Ruleset = new OsuRuleset().RulesetInfo,
             BeatmapInfo = beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First(),
-            Hash = replayAvailable ? "online" : string.Empty,
+            HasOnlineReplay = replayAvailable,
             User = new APIUser
             {
                 Id = 39828,
diff --git a/osu.Game/Scoring/IScoreInfo.cs b/osu.Game/Scoring/IScoreInfo.cs
index cde48c3be3..a1d076b8c2 100644
--- a/osu.Game/Scoring/IScoreInfo.cs
+++ b/osu.Game/Scoring/IScoreInfo.cs
@@ -22,8 +22,6 @@ public interface IScoreInfo : IHasOnlineID<long>
 
         double Accuracy { get; }
 
-        bool HasReplay { get; }
-
         long LegacyOnlineID { get; }
 
         DateTimeOffset Date { get; }
diff --git a/osu.Game/Scoring/ScoreInfo.cs b/osu.Game/Scoring/ScoreInfo.cs
index 722d83cac8..d712702331 100644
--- a/osu.Game/Scoring/ScoreInfo.cs
+++ b/osu.Game/Scoring/ScoreInfo.cs
@@ -94,8 +94,6 @@ public class ScoreInfo : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftD
 
         public double Accuracy { get; set; }
 
-        public bool HasReplay => !string.IsNullOrEmpty(Hash) || HasOnlineReplay;
-
         [Ignored]
         public bool HasOnlineReplay { get; set; }
 
diff --git a/osu.Game/Screens/Ranking/ReplayDownloadButton.cs b/osu.Game/Screens/Ranking/ReplayDownloadButton.cs
index b6166e97f6..df5f9c7a8a 100644
--- a/osu.Game/Screens/Ranking/ReplayDownloadButton.cs
+++ b/osu.Game/Screens/Ranking/ReplayDownloadButton.cs
@@ -37,7 +37,7 @@ private ReplayAvailability replayAvailability
                 if (State.Value == DownloadState.LocallyAvailable)
                     return ReplayAvailability.Local;
 
-                if (Score.Value?.HasReplay == true)
+                if (Score.Value?.HasOnlineReplay == true)
                     return ReplayAvailability.Online;
 
                 return ReplayAvailability.NotAvailable;

@bdach
Copy link
Collaborator Author

bdach commented Oct 27, 2023

I'm looking at the complexity around the replay flags and wondering why we can't switch to this:

Looks like we can because ScoreDownloadTracker was inlining the local case anyhow:

|| (!string.IsNullOrEmpty(s.Hash) && s.Hash == TrackedItem.Hash))

so, applied.

peppy
peppy previously approved these changes Oct 27, 2023
@peppy peppy enabled auto-merge October 27, 2023 11:04
@peppy peppy disabled auto-merge October 27, 2023 17:29
@peppy peppy merged commit 5a9d417 into ppy:master Oct 27, 2023
@bdach bdach deleted the score-encoding-cleanup branch October 27, 2023 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

The score is shown twice on the result screen Leaderboard replays are unavailable
2 participants