mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 07:22:55 +08:00
Reduce database includes where possible
This commit is contained in:
parent
0ffd9da6a9
commit
119000f1ab
@ -246,6 +246,12 @@ namespace osu.Game.Beatmaps
|
|||||||
if (beatmapInfo?.BeatmapSet == null || beatmapInfo == DefaultBeatmap?.BeatmapInfo)
|
if (beatmapInfo?.BeatmapSet == null || beatmapInfo == DefaultBeatmap?.BeatmapInfo)
|
||||||
return DefaultBeatmap;
|
return DefaultBeatmap;
|
||||||
|
|
||||||
|
if (beatmapInfo.BeatmapSet.Files == null)
|
||||||
|
{
|
||||||
|
var info = beatmapInfo;
|
||||||
|
beatmapInfo = QueryBeatmap(b => b.ID == info.ID);
|
||||||
|
}
|
||||||
|
|
||||||
lock (workingCache)
|
lock (workingCache)
|
||||||
{
|
{
|
||||||
var working = workingCache.FirstOrDefault(w => w.BeatmapInfo?.ID == beatmapInfo.ID);
|
var working = workingCache.FirstOrDefault(w => w.BeatmapInfo?.ID == beatmapInfo.ID);
|
||||||
@ -287,13 +293,34 @@ namespace osu.Game.Beatmaps
|
|||||||
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s.
|
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
|
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
|
||||||
public List<BeatmapSetInfo> GetAllUsableBeatmapSets() => GetAllUsableBeatmapSetsEnumerable().ToList();
|
public List<BeatmapSetInfo> GetAllUsableBeatmapSets(IncludedDetails includes = IncludedDetails.All) => GetAllUsableBeatmapSetsEnumerable(includes).ToList();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s.
|
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s. Note that files are not populated.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="includes">The level of detail to include in the returned objects.</param>
|
||||||
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
|
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
|
||||||
public IQueryable<BeatmapSetInfo> GetAllUsableBeatmapSetsEnumerable() => beatmaps.ConsumableItems.Where(s => !s.DeletePending && !s.Protected);
|
public IQueryable<BeatmapSetInfo> GetAllUsableBeatmapSetsEnumerable(IncludedDetails includes)
|
||||||
|
{
|
||||||
|
IQueryable<BeatmapSetInfo> queryable;
|
||||||
|
|
||||||
|
switch (includes)
|
||||||
|
{
|
||||||
|
case IncludedDetails.Minimal:
|
||||||
|
queryable = beatmaps.BeatmapSetsOverview;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IncludedDetails.AllButFiles:
|
||||||
|
queryable = beatmaps.BeatmapSetsWithoutFiles;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
queryable = beatmaps.ConsumableItems;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return queryable.Where(s => !s.DeletePending && !s.Protected);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Perform a lookup query on available <see cref="BeatmapSetInfo"/>s.
|
/// Perform a lookup query on available <see cref="BeatmapSetInfo"/>s.
|
||||||
@ -482,4 +509,25 @@ namespace osu.Game.Beatmaps
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The level of detail to include in database results.
|
||||||
|
/// </summary>
|
||||||
|
public enum IncludedDetails
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Only include beatmap difficulties and set level metadata.
|
||||||
|
/// </summary>
|
||||||
|
Minimal,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Include all difficulties, rulesets, difficulty metadata but no files.
|
||||||
|
/// </summary>
|
||||||
|
AllButFiles,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Include everything.
|
||||||
|
/// </summary>
|
||||||
|
All
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,18 @@ namespace osu.Game.Beatmaps
|
|||||||
base.Purge(items, context);
|
base.Purge(items, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IQueryable<BeatmapSetInfo> BeatmapSetsOverview => ContextFactory.Get().BeatmapSetInfo
|
||||||
|
.Include(s => s.Metadata)
|
||||||
|
.Include(s => s.Beatmaps)
|
||||||
|
.AsNoTracking();
|
||||||
|
|
||||||
|
public IQueryable<BeatmapSetInfo> BeatmapSetsWithoutFiles => ContextFactory.Get().BeatmapSetInfo
|
||||||
|
.Include(s => s.Metadata)
|
||||||
|
.Include(s => s.Beatmaps).ThenInclude(s => s.Ruleset)
|
||||||
|
.Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty)
|
||||||
|
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
|
||||||
|
.AsNoTracking();
|
||||||
|
|
||||||
public IQueryable<BeatmapInfo> Beatmaps =>
|
public IQueryable<BeatmapInfo> Beatmaps =>
|
||||||
ContextFactory.Get().BeatmapInfo
|
ContextFactory.Get().BeatmapInfo
|
||||||
.Include(b => b.BeatmapSet).ThenInclude(s => s.Metadata)
|
.Include(b => b.BeatmapSet).ThenInclude(s => s.Metadata)
|
||||||
|
@ -66,7 +66,7 @@ namespace osu.Game.Overlays
|
|||||||
beatmaps.ItemAdded += handleBeatmapAdded;
|
beatmaps.ItemAdded += handleBeatmapAdded;
|
||||||
beatmaps.ItemRemoved += handleBeatmapRemoved;
|
beatmaps.ItemRemoved += handleBeatmapRemoved;
|
||||||
|
|
||||||
beatmapSets.AddRange(beatmaps.GetAllUsableBeatmapSets().OrderBy(_ => RNG.Next()));
|
beatmapSets.AddRange(beatmaps.GetAllUsableBeatmapSets(IncludedDetails.Minimal).OrderBy(_ => RNG.Next()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
|
@ -73,7 +73,7 @@ namespace osu.Game.Screens.Menu
|
|||||||
|
|
||||||
if (!MenuMusic.Value)
|
if (!MenuMusic.Value)
|
||||||
{
|
{
|
||||||
var sets = beatmaps.GetAllUsableBeatmapSets();
|
var sets = beatmaps.GetAllUsableBeatmapSets(IncludedDetails.Minimal);
|
||||||
if (sets.Count > 0)
|
if (sets.Count > 0)
|
||||||
setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID);
|
setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID);
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ namespace osu.Game.Screens.Select
|
|||||||
loadBeatmapSets(GetLoadableBeatmaps());
|
loadBeatmapSets(GetLoadableBeatmaps());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual IEnumerable<BeatmapSetInfo> GetLoadableBeatmaps() => beatmaps.GetAllUsableBeatmapSetsEnumerable();
|
protected virtual IEnumerable<BeatmapSetInfo> GetLoadableBeatmaps() => beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.AllButFiles);
|
||||||
|
|
||||||
public void RemoveBeatmapSet(BeatmapSetInfo beatmapSet) => Schedule(() =>
|
public void RemoveBeatmapSet(BeatmapSetInfo beatmapSet) => Schedule(() =>
|
||||||
{
|
{
|
||||||
|
@ -286,7 +286,7 @@ namespace osu.Game.Screens.Select
|
|||||||
Schedule(() =>
|
Schedule(() =>
|
||||||
{
|
{
|
||||||
// if we have no beatmaps but osu-stable is found, let's prompt the user to import.
|
// if we have no beatmaps but osu-stable is found, let's prompt the user to import.
|
||||||
if (!beatmaps.GetAllUsableBeatmapSetsEnumerable().Any() && beatmaps.StableInstallationAvailable)
|
if (!beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.Minimal).Any() && beatmaps.StableInstallationAvailable)
|
||||||
{
|
{
|
||||||
dialogOverlay.Push(new ImportFromStablePopup(() =>
|
dialogOverlay.Push(new ImportFromStablePopup(() =>
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user