diff options
| author | Shadowghost <Ghost_of_Stone@web.de> | 2026-02-23 23:44:15 +0100 |
|---|---|---|
| committer | Shadowghost <Ghost_of_Stone@web.de> | 2026-02-23 23:44:15 +0100 |
| commit | 61ff36d761445db6b26f1a92147e3663bdf857a1 (patch) | |
| tree | 29a85f85ddb36ce86aa5bab938df619ea8d731f6 /Jellyfin.Server.Implementations/Item/OrderMapper.cs | |
| parent | 66c11231b209ade94831bc200f840b38aaba3160 (diff) | |
Optimize SeriesDatePlayed ordering
Diffstat (limited to 'Jellyfin.Server.Implementations/Item/OrderMapper.cs')
| -rw-r--r-- | Jellyfin.Server.Implementations/Item/OrderMapper.cs | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/Jellyfin.Server.Implementations/Item/OrderMapper.cs b/Jellyfin.Server.Implementations/Item/OrderMapper.cs index 05751e8fee..f48bbe43e1 100644 --- a/Jellyfin.Server.Implementations/Item/OrderMapper.cs +++ b/Jellyfin.Server.Implementations/Item/OrderMapper.cs @@ -57,26 +57,16 @@ public static class OrderMapper (ItemSortBy.VideoBitRate, _) => e => e.TotalBitrate, (ItemSortBy.ParentIndexNumber, _) => e => e.ParentIndexNumber, (ItemSortBy.IndexNumber, _) => e => e.IndexNumber, + // SeriesDatePlayed is normally handled via pre-aggregated join in ApplySeriesDatePlayedOrder. + // This correlated subquery fallback is only reached when combined with search. (ItemSortBy.SeriesDatePlayed, not null) => e => - jellyfinDbContext.BaseItems - .Where(w => w.SeriesPresentationUniqueKey == e.PresentationUniqueKey) - .LeftJoin( - jellyfinDbContext.UserData.Where(w => w.UserId == query.User.Id && w.Played), - item => item.Id, - userData => userData.ItemId, - (item, userData) => userData == null ? (DateTime?)null : userData.LastPlayedDate) - .Max(f => f), - (ItemSortBy.SeriesDatePlayed, null) => e => jellyfinDbContext.BaseItems.Where(w => w.SeriesPresentationUniqueKey == e.PresentationUniqueKey) - .LeftJoin( - jellyfinDbContext.UserData.Where(w => w.Played), - item => item.Id, - userData => userData.ItemId, - (item, userData) => userData == null ? (DateTime?)null : userData.LastPlayedDate) - .Max(f => f), - // ItemSortBy.SeriesDatePlayed => e => jellyfinDbContext.UserData - // .Where(u => u.Item!.SeriesPresentationUniqueKey == e.PresentationUniqueKey && u.Played) - // .Max(f => f.LastPlayedDate), - // ItemSortBy.AiredEpisodeOrder => "AiredEpisodeOrder", + jellyfinDbContext.UserData + .Where(w => w.UserId == query.User.Id && w.Played && w.Item!.SeriesPresentationUniqueKey == e.PresentationUniqueKey) + .Max(f => f.LastPlayedDate), + (ItemSortBy.SeriesDatePlayed, null) => e => + jellyfinDbContext.UserData + .Where(w => w.Played && w.Item!.SeriesPresentationUniqueKey == e.PresentationUniqueKey) + .Max(f => f.LastPlayedDate), _ => e => e.SortName }; } |
