mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 18:07:25 +08:00
Cache non-filtered beatmap counts to massively improve count performance
This commit is contained in:
parent
034c5cd654
commit
5755fa214a
@ -64,7 +64,7 @@ namespace osu.Game.Screens.Select
|
||||
/// <summary>
|
||||
/// The total count of non-filtered beatmaps displayed.
|
||||
/// </summary>
|
||||
public int CountDisplayed => beatmapSets.Where(s => !s.Filtered.Value).Sum(s => s.Beatmaps.Count(b => !b.Filtered.Value));
|
||||
public int CountDisplayed => beatmapSets.Where(s => !s.Filtered.Value).Sum(s => s.TotalItemsNotFiltered);
|
||||
|
||||
/// <summary>
|
||||
/// The currently selected beatmap set.
|
||||
|
@ -14,6 +14,8 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
|
||||
public IReadOnlyList<CarouselItem> Items => items;
|
||||
|
||||
public int TotalItemsNotFiltered { get; private set; }
|
||||
|
||||
private readonly List<CarouselItem> items = new List<CarouselItem>();
|
||||
|
||||
/// <summary>
|
||||
@ -31,6 +33,9 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
{
|
||||
items.Remove(i);
|
||||
|
||||
if (!i.Filtered.Value)
|
||||
TotalItemsNotFiltered--;
|
||||
|
||||
// it's important we do the deselection after removing, so any further actions based on
|
||||
// State.ValueChanged make decisions post-removal.
|
||||
i.State.Value = CarouselItemState.Collapsed;
|
||||
@ -55,6 +60,9 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
// criteria may be null for initial population. the filtering will be applied post-add.
|
||||
items.Add(i);
|
||||
}
|
||||
|
||||
if (!i.Filtered.Value)
|
||||
TotalItemsNotFiltered--;
|
||||
}
|
||||
|
||||
public CarouselGroup(List<CarouselItem>? items = null)
|
||||
@ -84,7 +92,14 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
{
|
||||
base.Filter(criteria);
|
||||
|
||||
items.ForEach(c => c.Filter(criteria));
|
||||
TotalItemsNotFiltered = 0;
|
||||
|
||||
foreach (var c in items)
|
||||
{
|
||||
c.Filter(criteria);
|
||||
if (!c.Filtered.Value)
|
||||
TotalItemsNotFiltered++;
|
||||
}
|
||||
|
||||
// Sorting is expensive, so only perform if it's actually changed.
|
||||
if (lastCriteria?.Sort != criteria.Sort)
|
||||
|
Loading…
Reference in New Issue
Block a user