From c77649d21e6bd53a662b217c6431b7d123d656b9 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Fri, 14 Aug 2026 07:39:49 +0200 Subject: Skip alternate version links when resolving link parents --- .../DescendantQueryHelper.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/Jellyfin.Database/Jellyfin.Database.Implementations/DescendantQueryHelper.cs') diff --git a/src/Jellyfin.Database/Jellyfin.Database.Implementations/DescendantQueryHelper.cs b/src/Jellyfin.Database/Jellyfin.Database.Implementations/DescendantQueryHelper.cs index 92adc37ccc..1e1c8780e8 100644 --- a/src/Jellyfin.Database/Jellyfin.Database.Implementations/DescendantQueryHelper.cs +++ b/src/Jellyfin.Database/Jellyfin.Database.Implementations/DescendantQueryHelper.cs @@ -177,9 +177,17 @@ public static class DescendantQueryHelper // Resolves the folders whose linked children lead, at any depth, to a matching item. private static List ResolveLinkParents(JellyfinDbContext context, IQueryable matchingItemIds, IQueryable ancestorsOfMatches) { + // An alternate version is a second file for the item that links it, not a child of it, so that + // edge is not walked. It is also the one link a non-folder owns, and there is one per remuxed + // movie: walking it would swell this list from the BoxSet and Playlist count to the item count, + // and the list is bound into every statement the returned queryable is embedded in. + var containerLinks = context.LinkedChildren + .Where(e => e.ChildType != LinkedChildType.LocalAlternateVersion + && e.ChildType != LinkedChildType.LinkedAlternateVersion); + // A link sits above the closure and above another link alike, so the hop repeats until nothing - // new turns up. Only link owners are collected, which bounds it by BoxSets and Playlists. - var resolved = context.LinkedChildren + // new turns up. + var resolved = containerLinks .Where(e => matchingItemIds.Contains(e.ChildId) || ancestorsOfMatches.Contains(e.ChildId)) .Select(e => e.ParentId) .Distinct() @@ -193,11 +201,11 @@ public static class DescendantQueryHelper .WhereOneOrMany(frontier, e => e.ItemId) .Select(e => e.ParentItemId); - var directLinkParents = context.LinkedChildren + var directLinkParents = containerLinks .WhereOneOrMany(frontier, e => e.ChildId) .Select(e => e.ParentId); - var indirectLinkParents = context.LinkedChildren + var indirectLinkParents = containerLinks .Where(e => containingFolders.Contains(e.ChildId)) .Select(e => e.ParentId); -- cgit v1.2.3