mirror of https://github.com/ppy/osu
Remove WorkingBeatmap cache when deleting or updating a beatmap
This commit is contained in:
parent
72ada020a2
commit
63003757c4
|
@ -79,6 +79,8 @@ public BeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, R
|
||||||
beatmaps = (BeatmapStore)ModelStore;
|
beatmaps = (BeatmapStore)ModelStore;
|
||||||
beatmaps.BeatmapHidden += b => beatmapHidden.Value = new WeakReference<BeatmapInfo>(b);
|
beatmaps.BeatmapHidden += b => beatmapHidden.Value = new WeakReference<BeatmapInfo>(b);
|
||||||
beatmaps.BeatmapRestored += b => beatmapRestored.Value = new WeakReference<BeatmapInfo>(b);
|
beatmaps.BeatmapRestored += b => beatmapRestored.Value = new WeakReference<BeatmapInfo>(b);
|
||||||
|
beatmaps.ItemRemoved += removeWorkingCache;
|
||||||
|
beatmaps.ItemUpdated += removeWorkingCache;
|
||||||
|
|
||||||
onlineLookupQueue = new BeatmapOnlineLookupQueue(api, storage);
|
onlineLookupQueue = new BeatmapOnlineLookupQueue(api, storage);
|
||||||
}
|
}
|
||||||
|
@ -206,9 +208,7 @@ public void Save(BeatmapInfo info, IBeatmap beatmapContent)
|
||||||
UpdateFile(setInfo, setInfo.Files.Single(f => string.Equals(f.Filename, info.Path, StringComparison.OrdinalIgnoreCase)), stream);
|
UpdateFile(setInfo, setInfo.Files.Single(f => string.Equals(f.Filename, info.Path, StringComparison.OrdinalIgnoreCase)), stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
var working = workingCache.FirstOrDefault(w => w.BeatmapInfo?.ID == info.ID);
|
removeWorkingCache(info);
|
||||||
if (working != null)
|
|
||||||
workingCache.Remove(working);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly WeakList<WorkingBeatmap> workingCache = new WeakList<WorkingBeatmap>();
|
private readonly WeakList<WorkingBeatmap> workingCache = new WeakList<WorkingBeatmap>();
|
||||||
|
@ -410,6 +410,24 @@ private double calculateLength(IBeatmap b)
|
||||||
return endTime - startTime;
|
return endTime - startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeWorkingCache(BeatmapSetInfo info)
|
||||||
|
{
|
||||||
|
if (info.Beatmaps == null) return;
|
||||||
|
|
||||||
|
foreach (var b in info.Beatmaps)
|
||||||
|
removeWorkingCache(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeWorkingCache(BeatmapInfo info)
|
||||||
|
{
|
||||||
|
lock (workingCache)
|
||||||
|
{
|
||||||
|
var working = workingCache.FirstOrDefault(w => w.BeatmapInfo?.ID == info.ID);
|
||||||
|
if (working != null)
|
||||||
|
workingCache.Remove(working);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
onlineLookupQueue?.Dispose();
|
onlineLookupQueue?.Dispose();
|
||||||
|
|
Loading…
Reference in New Issue