mirror of
https://github.com/ppy/osu
synced 2024-12-26 17:02:59 +00:00
Avoid file retrieval overhead when detaching BeatmapSetInfo
It seems that no usages of `BeatmapSetInfo` detaches require files - a `WorkingBeatmap` is always obtained before doing further lookups. Therefore we can omit this include unless the detaching object is a `BeatmapInfo`. A refetch is performed when retrieving a `WorkingBeatmap` to complete the equation.
This commit is contained in:
parent
f2b151023e
commit
60b80c88b6
@ -299,7 +299,23 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
#region Implementation of IWorkingBeatmapCache
|
||||
|
||||
public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo? importedBeatmap) => workingBeatmapCache.GetWorkingBeatmap(importedBeatmap);
|
||||
public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo? importedBeatmap)
|
||||
{
|
||||
// Detached sets don't come with files.
|
||||
// If we seem to be missing files, now is a good time to re-fetch.
|
||||
if (importedBeatmap?.BeatmapSet?.Files.Count == 0)
|
||||
{
|
||||
using (var realm = contextFactory.CreateContext())
|
||||
{
|
||||
var refetch = realm.Find<BeatmapInfo>(importedBeatmap.ID)?.Detach();
|
||||
|
||||
if (refetch != null)
|
||||
importedBeatmap = refetch;
|
||||
}
|
||||
}
|
||||
|
||||
return workingBeatmapCache.GetWorkingBeatmap(importedBeatmap);
|
||||
}
|
||||
|
||||
public WorkingBeatmap GetWorkingBeatmap(ILive<BeatmapInfo>? importedBeatmap)
|
||||
{
|
||||
|
@ -76,6 +76,14 @@ namespace osu.Game.Database
|
||||
{
|
||||
applyCommonConfiguration(c);
|
||||
|
||||
c.CreateMap<BeatmapSetInfo, BeatmapSetInfo>()
|
||||
.MaxDepth(2)
|
||||
.AfterMap((s, d) =>
|
||||
{
|
||||
foreach (var beatmap in d.Beatmaps)
|
||||
beatmap.BeatmapSet = d;
|
||||
});
|
||||
|
||||
// This can be further optimised to reduce cyclic retrievals, similar to the optimised set mapper below.
|
||||
// Only hasn't been done yet as we detach at the point of BeatmapInfo less often.
|
||||
c.CreateMap<BeatmapInfo, BeatmapInfo>()
|
||||
@ -100,6 +108,15 @@ namespace osu.Game.Database
|
||||
{
|
||||
applyCommonConfiguration(c);
|
||||
|
||||
c.CreateMap<BeatmapSetInfo, BeatmapSetInfo>()
|
||||
.MaxDepth(2)
|
||||
.ForMember(b => b.Files, cc => cc.Ignore())
|
||||
.AfterMap((s, d) =>
|
||||
{
|
||||
foreach (var beatmap in d.Beatmaps)
|
||||
beatmap.BeatmapSet = d;
|
||||
});
|
||||
|
||||
c.CreateMap<BeatmapInfo, BeatmapInfo>()
|
||||
.MaxDepth(1)
|
||||
.ForMember(b => b.BeatmapSet, cc => cc.Ignore());
|
||||
@ -131,13 +148,6 @@ namespace osu.Game.Database
|
||||
c.CreateMap<RealmUser, RealmUser>();
|
||||
c.CreateMap<RealmFile, RealmFile>();
|
||||
c.CreateMap<RealmNamedFileUsage, RealmNamedFileUsage>();
|
||||
c.CreateMap<BeatmapSetInfo, BeatmapSetInfo>()
|
||||
.MaxDepth(2)
|
||||
.AfterMap((s, d) =>
|
||||
{
|
||||
foreach (var beatmap in d.Beatmaps)
|
||||
beatmap.BeatmapSet = d;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user