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

Fix watch replay button sometimes not loading the replay on first click #30895

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion osu.Game/Beatmaps/BeatmapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,11 @@ public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo? beatmapInfo, bool refetch =
// If we seem to be missing files, now is a good time to re-fetch.
bool missingFiles = beatmapInfo.BeatmapSet?.Files.Count == 0;

if (refetch || beatmapInfo.IsManaged || missingFiles)
if (beatmapInfo.IsManaged)
{
beatmapInfo = beatmapInfo.Detach();
}
else if (refetch || missingFiles)
Comment on lines +562 to +566
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes me nervous but I don't have any concrete reason to doubt it so I'm just gonna hope this breaks nothing

{
Guid id = beatmapInfo.ID;
beatmapInfo = Realm.Run(r => r.Find<BeatmapInfo>(id)?.Detach()) ?? beatmapInfo;
Expand Down
12 changes: 9 additions & 3 deletions osu.Game/Scoring/ScoreManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public ScoreManager(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storag
/// Perform a lookup query on available <see cref="ScoreInfo"/>s.
/// </summary>
/// <param name="query">The query.</param>
/// <returns>The first result for the provided query, or null if no results were found.</returns>
/// <returns>The first result for the provided query in its detached form, or null if no results were found.</returns>
public ScoreInfo? Query(Expression<Func<ScoreInfo, bool>> query)
{
return Realm.Run(r => r.All<ScoreInfo>().FirstOrDefault(query)?.Detach());
Expand All @@ -88,8 +88,14 @@ public ScoreManager(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storag
{
ScoreInfo? databasedScoreInfo = null;

if (originalScoreInfo is ScoreInfo scoreInfo && !string.IsNullOrEmpty(scoreInfo.Hash))
databasedScoreInfo = Query(s => s.Hash == scoreInfo.Hash);
if (originalScoreInfo is ScoreInfo scoreInfo)
{
if (scoreInfo.IsManaged)
return scoreInfo.Detach();

if (!string.IsNullOrEmpty(scoreInfo.Hash))
databasedScoreInfo = Query(s => s.Hash == scoreInfo.Hash);
}

if (originalScoreInfo.OnlineID > 0)
databasedScoreInfo ??= Query(s => s.OnlineID == originalScoreInfo.OnlineID);
Expand Down
10 changes: 5 additions & 5 deletions osu.Game/Screens/Play/SaveFailedScoreButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public partial class SaveFailedScoreButton : CompositeDrawable, IKeyBindingHandl

private readonly Func<Task<ScoreInfo>>? importFailedScore;

private ScoreInfo? importedScore;
private Live<ScoreInfo>? importedScore;

private DownloadButton button = null!;

Expand All @@ -55,7 +55,7 @@ private void load(OsuGame? game, Player? player)
switch (state.Value)
{
case DownloadState.LocallyAvailable:
game?.PresentScore(importedScore, ScorePresentType.Gameplay);
game?.PresentScore(importedScore?.Value, ScorePresentType.Gameplay);
break;

case DownloadState.NotDownloaded:
Expand All @@ -65,7 +65,7 @@ private void load(OsuGame? game, Player? player)
{
Task.Run(importFailedScore).ContinueWith(t =>
{
importedScore = realm.Run(r => r.Find<ScoreInfo>(t.GetResultSafely().ID)?.Detach());
importedScore = realm.Run<Live<ScoreInfo>?>(r => r.Find<ScoreInfo>(t.GetResultSafely().ID)?.ToLive(realm));
Schedule(() => state.Value = importedScore != null ? DownloadState.LocallyAvailable : DownloadState.NotDownloaded);
}).FireAndForget();
}
Expand All @@ -77,7 +77,7 @@ private void load(OsuGame? game, Player? player)

if (player != null)
{
importedScore = realm.Run(r => r.Find<ScoreInfo>(player.Score.ScoreInfo.ID)?.Detach());
importedScore = realm.Run(r => r.Find<ScoreInfo>(player.Score.ScoreInfo.ID)?.ToLive(realm));
state.Value = importedScore != null ? DownloadState.LocallyAvailable : DownloadState.NotDownloaded;
}

Expand Down Expand Up @@ -137,7 +137,7 @@ private void exportWhenReady(ValueChangedEvent<DownloadState> state)
{
if (state.NewValue != DownloadState.LocallyAvailable) return;

if (importedScore != null) scoreManager.Export(importedScore);
if (importedScore != null) scoreManager.Export(importedScore.Value);

this.state.ValueChanged -= exportWhenReady;
}
Expand Down
Loading