diff options
| author | Bond-009 <bond.009@outlook.com> | 2026-07-20 08:17:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-20 08:17:38 +0200 |
| commit | 236db6d2f6332373759c309c5ec722b1e416aa59 (patch) | |
| tree | c30d7e9ead7a961f49365c581fcb88a8f722f42f /Jellyfin.Server.Implementations/Item/BaseItemRepository.TranslateQuery.cs | |
| parent | 181c057cb8cca857585505f010034e462b9b094e (diff) | |
| parent | cdf7ce0fc4504eda29a2b4060fbe1fe628e2ee0a (diff) | |
Merge pull request #17365 from Shadowghost/fix-resume-perf
Fix Resume query performance
Diffstat (limited to 'Jellyfin.Server.Implementations/Item/BaseItemRepository.TranslateQuery.cs')
| -rw-r--r-- | Jellyfin.Server.Implementations/Item/BaseItemRepository.TranslateQuery.cs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Jellyfin.Server.Implementations/Item/BaseItemRepository.TranslateQuery.cs b/Jellyfin.Server.Implementations/Item/BaseItemRepository.TranslateQuery.cs index 52cebccc37..1198f99473 100644 --- a/Jellyfin.Server.Implementations/Item/BaseItemRepository.TranslateQuery.cs +++ b/Jellyfin.Server.Implementations/Item/BaseItemRepository.TranslateQuery.cs @@ -557,8 +557,13 @@ public sealed partial class BaseItemRepository : baseQuery.Where(e => inProgressIds.Contains(e.Id)); // When several versions of the same item are in progress, keep only the most recently played one, use id as tiebreaker. + // Only in-progress siblings can eliminate a candidate: a version without progress has a NULL max LastPlayedDate, + // which is never greater and never ties. Restricting the sibling scan to the in-progress set keeps this bounded by + // the user's Continue Watching count instead of forcing a full BaseItems scan (COALESCE keys are non-indexable) per row. baseQuery = baseQuery.Where(e => e.Type == seriesTypeName || !context.BaseItems - .Where(s => s.Id != e.Id && (s.PrimaryVersionId ?? s.Id) == (e.PrimaryVersionId ?? e.Id)) + .Where(s => s.Id != e.Id + && inProgressIds.Contains(s.Id) + && (s.PrimaryVersionId ?? s.Id) == (e.PrimaryVersionId ?? e.Id)) .Any(s => inProgress.Where(su => su.ItemId == s.Id).Max(su => su.LastPlayedDate) > inProgress.Where(eu => eu.ItemId == e.Id).Max(eu => eu.LastPlayedDate) |
