aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server.Implementations/Item
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2026-02-20 21:21:25 +0100
committerShadowghost <Ghost_of_Stone@web.de>2026-02-20 21:21:25 +0100
commit561e78efb40c2025bdd02df87da7d456cf97c045 (patch)
tree9b7a0916e8290aac7c90a496b77294eec6accdb3 /Jellyfin.Server.Implementations/Item
parentff0a64ecb9dd4960478c97150e566c8953c447bf (diff)
Apply review suggestions
Diffstat (limited to 'Jellyfin.Server.Implementations/Item')
-rw-r--r--Jellyfin.Server.Implementations/Item/BaseItemRepository.cs43
1 files changed, 22 insertions, 21 deletions
diff --git a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs
index e05f4c45dc..2c0ec69941 100644
--- a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs
+++ b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs
@@ -375,30 +375,29 @@ public sealed class BaseItemRepository
// Find the top N group keys ordered by most recent DateCreated.
// Movies group by PresentationUniqueKey (alternate versions like 4K/1080p share a key).
// Music groups by Album.
- List<string> topGroupKeys;
+ Expression<Func<BaseItemEntity, bool>> groupKeyFilter;
+ Expression<Func<BaseItemEntity, string?>> groupKeySelector;
+
if (collectionType is CollectionType.movies)
{
- topGroupKeys = baseQuery
- .Where(e => e.PresentationUniqueKey != null)
- .GroupBy(e => e.PresentationUniqueKey)
- .Select(g => new { GroupKey = g.Key!, MaxDate = g.Max(e => e.DateCreated) })
- .OrderByDescending(g => g.MaxDate)
- .Take(limit)
- .Select(g => g.GroupKey)
- .ToList();
+ groupKeyFilter = e => e.PresentationUniqueKey != null;
+ groupKeySelector = e => e.PresentationUniqueKey;
}
else
{
- topGroupKeys = baseQuery
- .Where(e => e.Album != null)
- .GroupBy(e => e.Album)
- .Select(g => new { GroupKey = g.Key!, MaxDate = g.Max(e => e.DateCreated) })
- .OrderByDescending(g => g.MaxDate)
- .Take(limit)
- .Select(g => g.GroupKey)
- .ToList();
+ groupKeyFilter = e => e.Album != null;
+ groupKeySelector = e => e.Album;
}
+ var topGroupKeys = baseQuery
+ .Where(groupKeyFilter)
+ .GroupBy(groupKeySelector)
+ .Select(g => new { GroupKey = g.Key!, MaxDate = g.Max(e => e.DateCreated) })
+ .OrderByDescending(g => g.MaxDate)
+ .Take(limit)
+ .Select(g => g.GroupKey)
+ .ToList();
+
// Get only the first (most recent) item ID per group using a lightweight projection,
// then fetch full entities only for those items. This avoids loading all versions/tracks
// with expensive navigation properties just to discard duplicates.
@@ -1422,13 +1421,13 @@ public sealed class BaseItemRepository
.ToArray();
var lookup = _itemTypeLookup.BaseItemKindNames;
- var result = new ItemCounts
- {
- ItemCount = counts.Sum(c => c.Count)
- };
+ var result = new ItemCounts();
+ var totalCount = 0;
foreach (var count in counts)
{
+ totalCount += count.Count;
+
if (string.Equals(count.Key, lookup[BaseItemKind.MusicAlbum], StringComparison.Ordinal))
{
result.AlbumCount = count.Count;
@@ -1475,6 +1474,8 @@ public sealed class BaseItemRepository
}
}
+ result.ItemCount = totalCount;
+
return result;
}