mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 09:23:06 +08:00
Simplify refetch (and ensure to invalidate after processing)
This commit is contained in:
parent
0c3d890f76
commit
7692bac35a
@ -430,26 +430,30 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
#region Implementation of IWorkingBeatmapCache
|
#region Implementation of IWorkingBeatmapCache
|
||||||
|
|
||||||
public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo? beatmapInfo)
|
/// <summary>
|
||||||
|
/// Retrieve a <see cref="WorkingBeatmap"/> instance for the provided <see cref="BeatmapInfo"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="beatmapInfo">The beatmap to lookup.</param>
|
||||||
|
/// <param name="refetch">Whether to force a refetch from the database to ensure <see cref="BeatmapInfo"/> is up-to-date.</param>
|
||||||
|
/// <returns>A <see cref="WorkingBeatmap"/> instance correlating to the provided <see cref="BeatmapInfo"/>.</returns>
|
||||||
|
public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo, bool refetch = false)
|
||||||
{
|
{
|
||||||
// Detached sets don't come with files.
|
// Detached sets don't come with files.
|
||||||
// If we seem to be missing files, now is a good time to re-fetch.
|
// If we seem to be missing files, now is a good time to re-fetch.
|
||||||
if (beatmapInfo?.IsManaged == true || beatmapInfo?.BeatmapSet?.Files.Count == 0)
|
if (refetch || beatmapInfo.IsManaged || beatmapInfo.BeatmapSet?.Files.Count == 0)
|
||||||
{
|
{
|
||||||
Realm.Run(r =>
|
workingBeatmapCache.Invalidate(beatmapInfo);
|
||||||
{
|
|
||||||
var refetch = r.Find<BeatmapInfo>(beatmapInfo.ID)?.Detach();
|
|
||||||
|
|
||||||
if (refetch != null)
|
Guid id = beatmapInfo.ID;
|
||||||
beatmapInfo = refetch;
|
beatmapInfo = Realm.Run(r => r.Find<BeatmapInfo>(id)?.Detach()) ?? beatmapInfo;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Assert(beatmapInfo?.IsManaged != true);
|
Debug.Assert(beatmapInfo.IsManaged != true);
|
||||||
|
|
||||||
return workingBeatmapCache.GetWorkingBeatmap(beatmapInfo);
|
return workingBeatmapCache.GetWorkingBeatmap(beatmapInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WorkingBeatmap IWorkingBeatmapCache.GetWorkingBeatmap(BeatmapInfo beatmapInfo) => GetWorkingBeatmap(beatmapInfo);
|
||||||
void IWorkingBeatmapCache.Invalidate(BeatmapSetInfo beatmapSetInfo) => workingBeatmapCache.Invalidate(beatmapSetInfo);
|
void IWorkingBeatmapCache.Invalidate(BeatmapSetInfo beatmapSetInfo) => workingBeatmapCache.Invalidate(beatmapSetInfo);
|
||||||
void IWorkingBeatmapCache.Invalidate(BeatmapInfo beatmapInfo) => workingBeatmapCache.Invalidate(beatmapInfo);
|
void IWorkingBeatmapCache.Invalidate(BeatmapInfo beatmapInfo) => workingBeatmapCache.Invalidate(beatmapInfo);
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
difficultyCache.Invalidate(beatmap);
|
difficultyCache.Invalidate(beatmap);
|
||||||
|
|
||||||
var working = workingBeatmapCache.GetWorkingBeatmap(beatmap.Detach());
|
var working = workingBeatmapCache.GetWorkingBeatmap(beatmap);
|
||||||
var ruleset = working.BeatmapInfo.Ruleset.CreateInstance();
|
var ruleset = working.BeatmapInfo.Ruleset.CreateInstance();
|
||||||
|
|
||||||
Debug.Assert(ruleset != null);
|
Debug.Assert(ruleset != null);
|
||||||
@ -65,6 +65,9 @@ namespace osu.Game.Beatmaps
|
|||||||
beatmap.Length = calculateLength(working.Beatmap);
|
beatmap.Length = calculateLength(working.Beatmap);
|
||||||
beatmap.BPM = 60000 / working.Beatmap.GetMostCommonBeatLength();
|
beatmap.BPM = 60000 / working.Beatmap.GetMostCommonBeatLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// And invalidate again afterwards as re-fetching the most up-to-date database metadata will be required.
|
||||||
|
workingBeatmapCache.Invalidate(beatmapSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double calculateLength(IBeatmap b)
|
private double calculateLength(IBeatmap b)
|
||||||
|
@ -630,9 +630,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
// To update the game-wide beatmap with any changes, perform a re-fetch on exit/suspend.
|
// To update the game-wide beatmap with any changes, perform a re-fetch on exit/suspend.
|
||||||
// This is required as the editor makes its local changes via EditorBeatmap
|
// This is required as the editor makes its local changes via EditorBeatmap
|
||||||
// (which are not propagated outwards to a potentially cached WorkingBeatmap).
|
// (which are not propagated outwards to a potentially cached WorkingBeatmap).
|
||||||
((IWorkingBeatmapCache)beatmapManager).Invalidate(Beatmap.Value.BeatmapInfo);
|
var refetchedBeatmap = beatmapManager.GetWorkingBeatmap(Beatmap.Value.BeatmapInfo, true);
|
||||||
var refetchedBeatmapInfo = beatmapManager.QueryBeatmap(b => b.ID == Beatmap.Value.BeatmapInfo.ID);
|
|
||||||
var refetchedBeatmap = beatmapManager.GetWorkingBeatmap(refetchedBeatmapInfo);
|
|
||||||
|
|
||||||
if (!(refetchedBeatmap is DummyWorkingBeatmap))
|
if (!(refetchedBeatmap is DummyWorkingBeatmap))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user