diff --git a/osu.Game.Tests/Visual/SongSelectV2/BeatmapCarouselFilterGroupingTest.cs b/osu.Game.Tests/Visual/SongSelectV2/BeatmapCarouselFilterGroupingTest.cs index 1791d2a24c..939a5e6e7c 100644 --- a/osu.Game.Tests/Visual/SongSelectV2/BeatmapCarouselFilterGroupingTest.cs +++ b/osu.Game.Tests/Visual/SongSelectV2/BeatmapCarouselFilterGroupingTest.cs @@ -368,7 +368,7 @@ namespace osu.Game.Tests.Visual.SongSelectV2 var groupingFilter = new BeatmapCarouselFilterGrouping( () => new FilterCriteria { Group = group }, () => new List(), - (_, _) => new Dictionary()); + _ => new Dictionary()); return await groupingFilter.Run(beatmapSets.SelectMany(s => s.Beatmaps.Select(b => new CarouselItem(b))).ToList(), CancellationToken.None); } diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs index 1f4d370d13..a6b40a26de 100644 --- a/osu.Game/Beatmaps/BeatmapInfo.cs +++ b/osu.Game/Beatmaps/BeatmapInfo.cs @@ -157,12 +157,6 @@ namespace osu.Game.Beatmaps public bool Equals(IBeatmapInfo? other) => other is BeatmapInfo b && Equals(b); - public override int GetHashCode() - { - // ReSharper disable once NonReadonlyMemberInGetHashCode - return ID.GetHashCode(); - } - public bool AudioEquals(BeatmapInfo? other) => other != null && BeatmapSet != null && other.BeatmapSet != null diff --git a/osu.Game/Screens/SelectV2/BeatmapCarousel.cs b/osu.Game/Screens/SelectV2/BeatmapCarousel.cs index e663002ff5..bdb0f86d85 100644 --- a/osu.Game/Screens/SelectV2/BeatmapCarousel.cs +++ b/osu.Game/Screens/SelectV2/BeatmapCarousel.cs @@ -102,7 +102,7 @@ namespace osu.Game.Screens.SelectV2 { new BeatmapCarouselFilterMatching(() => Criteria!), new BeatmapCarouselFilterSorting(() => Criteria!), - grouping = new BeatmapCarouselFilterGrouping(() => Criteria!, getDetachedCollections, buildTopRankMapping) + grouping = new BeatmapCarouselFilterGrouping(() => Criteria!, getDetachedCollections, getTopRanksMapping) }; AddInternal(loading = new LoadingLayer()); @@ -625,14 +625,14 @@ namespace osu.Game.Screens.SelectV2 #endregion - #region Grouping + #region Database fetches for grouping support [Resolved] private RealmAccess realm { get; set; } = null!; - private List getDetachedCollections() => realm.Run(r => r.All().Detach()); + private List getDetachedCollections() => realm.Run(r => r.All().AsEnumerable().Detach()); - private Dictionary buildTopRankMapping(int? localUserId, string? ruleset) => realm.Run(r => + private Dictionary getTopRanksMapping(FilterCriteria criteria) => realm.Run(r => { var topRankMapping = new Dictionary(); @@ -640,7 +640,7 @@ namespace osu.Game.Screens.SelectV2 .Filter($"{nameof(ScoreInfo.User)}.{nameof(RealmUser.OnlineID)} == $0" + $" && {nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.Hash)} == {nameof(ScoreInfo.BeatmapHash)}" + $" && {nameof(ScoreInfo.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $1" - + $" && {nameof(ScoreInfo.DeletePending)} == false", localUserId, ruleset) + + $" && {nameof(ScoreInfo.DeletePending)} == false", criteria.LocalUserId, criteria.Ruleset?.ShortName) .OrderByDescending(s => s.TotalScore) .ThenBy(s => s.Date); diff --git a/osu.Game/Screens/SelectV2/BeatmapCarouselFilterGrouping.cs b/osu.Game/Screens/SelectV2/BeatmapCarouselFilterGrouping.cs index 85a11b78bb..6be620899b 100644 --- a/osu.Game/Screens/SelectV2/BeatmapCarouselFilterGrouping.cs +++ b/osu.Game/Screens/SelectV2/BeatmapCarouselFilterGrouping.cs @@ -40,14 +40,14 @@ namespace osu.Game.Screens.SelectV2 private Dictionary> groupMap = new Dictionary>(); private readonly Func getCriteria; - private readonly GetDetachedCollectionsDelegate getDetachedCollections; - private readonly BuildTopRankMappingDelegate buildTopRankMapping; + private readonly Func> getCollections; + private readonly Func> getLocalUserTopRanks; - public BeatmapCarouselFilterGrouping(Func getCriteria, GetDetachedCollectionsDelegate getDetachedCollections, BuildTopRankMappingDelegate buildTopRankMapping) + public BeatmapCarouselFilterGrouping(Func getCriteria, Func> getCollections, Func> getLocalUserTopRanks) { this.getCriteria = getCriteria; - this.getDetachedCollections = getDetachedCollections; - this.buildTopRankMapping = buildTopRankMapping; + this.getCollections = getCollections; + this.getLocalUserTopRanks = getLocalUserTopRanks; } public async Task> Run(IEnumerable items, CancellationToken cancellationToken) @@ -190,7 +190,7 @@ namespace osu.Game.Screens.SelectV2 var date = b.LastPlayed; if (BeatmapSetsGroupedTogether) - date = aggregateMax(b, static b => (b.LastPlayed ?? DateTimeOffset.MinValue)); + date = aggregateMax(b, static b => b.LastPlayed ?? DateTimeOffset.MinValue); if (date == null || date == DateTimeOffset.MinValue) return new GroupDefinition(int.MaxValue, "Never"); @@ -231,7 +231,7 @@ namespace osu.Game.Screens.SelectV2 case GroupMode.Collections: { - var collections = getDetachedCollections(); + var collections = getCollections(); return getGroupsBy(b => defineGroupByCollection(b, collections), items); } @@ -240,7 +240,7 @@ namespace osu.Game.Screens.SelectV2 case GroupMode.RankAchieved: { - var topRankMapping = buildTopRankMapping(criteria.LocalUserId, criteria.Ruleset?.ShortName); + var topRankMapping = getLocalUserTopRanks(criteria); return getGroupsBy(b => defineGroupByRankAchieved(b, topRankMapping), items); } @@ -440,9 +440,5 @@ namespace osu.Game.Screens.SelectV2 } private record GroupMapping(GroupDefinition? Group, List ItemsInGroup); - - public delegate List GetDetachedCollectionsDelegate(); - - public delegate IReadOnlyDictionary BuildTopRankMappingDelegate(int? localUserId, string? ruleset); } }