1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-05 10:33:22 +08:00

Merge pull request #30895 from peppy/watch-replay-reliability

Fix watch replay button sometimes not loading the replay on first click
This commit is contained in:
Bartłomiej Dach 2024-11-28 13:16:40 +01:00 committed by GitHub
commit d0e80ce982
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 9 deletions

View File

@ -559,7 +559,11 @@ namespace osu.Game.Beatmaps
// 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;

View File

@ -78,7 +78,7 @@ namespace osu.Game.Scoring
/// 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());
@ -88,8 +88,14 @@ namespace osu.Game.Scoring
{
ScoreInfo? databasedScoreInfo = null;
if (originalScoreInfo is ScoreInfo scoreInfo && !string.IsNullOrEmpty(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);

View File

@ -32,7 +32,7 @@ namespace osu.Game.Screens.Play
private readonly Func<Task<ScoreInfo>>? importFailedScore;
private ScoreInfo? importedScore;
private Live<ScoreInfo>? importedScore;
private DownloadButton button = null!;
@ -55,7 +55,7 @@ namespace osu.Game.Screens.Play
switch (state.Value)
{
case DownloadState.LocallyAvailable:
game?.PresentScore(importedScore, ScorePresentType.Gameplay);
game?.PresentScore(importedScore?.Value, ScorePresentType.Gameplay);
break;
case DownloadState.NotDownloaded:
@ -65,7 +65,7 @@ namespace osu.Game.Screens.Play
{
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();
}
@ -77,7 +77,7 @@ namespace osu.Game.Screens.Play
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;
}
@ -137,7 +137,7 @@ namespace osu.Game.Screens.Play
{
if (state.NewValue != DownloadState.LocallyAvailable) return;
if (importedScore != null) scoreManager.Export(importedScore);
if (importedScore != null) scoreManager.Export(importedScore.Value);
this.state.ValueChanged -= exportWhenReady;
}