1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:07:38 +08:00

Merge pull request #5196 from peppy/reduce-db-contexts

Change song select initialisation to promote database context sharing
This commit is contained in:
Dan Balasescu 2019-07-02 00:04:12 +09:30 committed by GitHub
commit 5531810182
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 26 deletions

View File

@ -11,7 +11,6 @@ using osu.Game.Configuration;
using osuTK.Input;
using osu.Framework.MathUtils;
using System.Diagnostics;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Caching;
@ -64,35 +63,29 @@ namespace osu.Game.Screens.Select
public IEnumerable<BeatmapSetInfo> BeatmapSets
{
get => beatmapSets.Select(g => g.BeatmapSet);
set => loadBeatmapSets(() => value);
set => loadBeatmapSets(value);
}
public void LoadBeatmapSetsFromManager(BeatmapManager manager) => loadBeatmapSets(manager.GetAllUsableBeatmapSetsEnumerable);
private void loadBeatmapSets(Func<IEnumerable<BeatmapSetInfo>> beatmapSets)
private void loadBeatmapSets(IEnumerable<BeatmapSetInfo> beatmapSets)
{
CarouselRoot newRoot = new CarouselRoot(this);
Task.Run(() =>
{
beatmapSets().Select(createCarouselSet).Where(g => g != null).ForEach(newRoot.AddChild);
newRoot.Filter(activeCriteria);
beatmapSets.Select(createCarouselSet).Where(g => g != null).ForEach(newRoot.AddChild);
newRoot.Filter(activeCriteria);
// preload drawables as the ctor overhead is quite high currently.
var _ = newRoot.Drawables;
}).ContinueWith(_ => Schedule(() =>
{
root = newRoot;
scrollableContent.Clear(false);
itemsCache.Invalidate();
scrollPositionCache.Invalidate();
// preload drawables as the ctor overhead is quite high currently.
var _ = newRoot.Drawables;
Schedule(() =>
{
BeatmapSetsChanged?.Invoke();
BeatmapSetsLoaded = true;
});
}));
root = newRoot;
scrollableContent.Clear(false);
itemsCache.Invalidate();
scrollPositionCache.Invalidate();
Schedule(() =>
{
BeatmapSetsChanged?.Invoke();
BeatmapSetsLoaded = true;
});
}
private readonly List<float> yPositions = new List<float>();
@ -125,13 +118,15 @@ namespace osu.Game.Screens.Select
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuConfigManager config)
private void load(OsuConfigManager config, BeatmapManager beatmaps)
{
config.BindWith(OsuSetting.RandomSelectAlgorithm, RandomAlgorithm);
config.BindWith(OsuSetting.SongSelectRightMouseScroll, RightClickScrollingEnabled);
RightClickScrollingEnabled.ValueChanged += enabled => RightMouseScrollbar = enabled.NewValue;
RightClickScrollingEnabled.TriggerChange();
loadBeatmapSets(beatmaps.GetAllUsableBeatmapSetsEnumerable());
}
public void RemoveBeatmapSet(BeatmapSetInfo beatmapSet)

View File

@ -244,8 +244,6 @@ namespace osu.Game.Screens.Select
sampleChangeBeatmap = audio.Samples.Get(@"SongSelect/select-expand");
SampleConfirm = audio.Samples.Get(@"SongSelect/confirm-selection");
Carousel.LoadBeatmapSetsFromManager(this.beatmaps);
if (dialogOverlay != null)
{
Schedule(() =>