Skip to content

Commit

Permalink
Merge pull request #30895 from peppy/watch-replay-reliability
Browse files Browse the repository at this point in the history
Fix watch replay button sometimes not loading the replay on first click
  • Loading branch information
bdach authored Nov 28, 2024
2 parents 98a156a + 5260a40 commit d0e80ce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
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)
{
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

0 comments on commit d0e80ce

Please sign in to comment.