1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Add back caching in WorkingBeatmapCache

This commit is contained in:
Dean Herbert 2022-01-11 14:40:47 +09:00
parent 286994a808
commit 2ce80cc030

View File

@ -12,6 +12,7 @@ using osu.Framework.IO.Stores;
using osu.Framework.Lists;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Framework.Statistics;
using osu.Framework.Testing;
using osu.Game.Beatmaps.Formats;
using osu.Game.Database;
@ -75,21 +76,27 @@ namespace osu.Game.Beatmaps
public virtual WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo)
{
// if there are no files, presume the full beatmap info has not yet been fetched from the database.
if (beatmapInfo?.BeatmapSet?.Files.Count == 0)
{
var lookupId = beatmapInfo.ID;
beatmapInfo = BeatmapManager.QueryBeatmap(b => b.ID == lookupId);
}
// TODO: FUCK THE WORLD :D
if (beatmapInfo?.IsManaged == true)
beatmapInfo = beatmapInfo.Detach();
if (beatmapInfo?.BeatmapSet == null)
return DefaultBeatmap;
return new BeatmapManagerWorkingBeatmap(beatmapInfo, this);
lock (workingCache)
{
var working = workingCache.FirstOrDefault(w => beatmapInfo.Equals(w.BeatmapInfo));
if (working != null)
return working;
// TODO: FUCK THE WORLD :D
if (beatmapInfo?.IsManaged == true)
beatmapInfo = beatmapInfo.Detach();
workingCache.Add(working = new BeatmapManagerWorkingBeatmap(beatmapInfo, this));
// best effort; may be higher than expected.
GlobalStatistics.Get<int>("Beatmaps", $"Cached {nameof(WorkingBeatmap)}s").Value = workingCache.Count();
return working;
}
}
#region IResourceStorageProvider