From 744c5539d8471addca131c9d9f7e8c4e30f8c4b5 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Thu, 5 Mar 2026 22:54:26 +0100 Subject: Fix review comments --- .../DescendantQueryHelper.cs | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/Jellyfin.Database/Jellyfin.Database.Implementations') diff --git a/src/Jellyfin.Database/Jellyfin.Database.Implementations/DescendantQueryHelper.cs b/src/Jellyfin.Database/Jellyfin.Database.Implementations/DescendantQueryHelper.cs index 3bc36dca7a..43e6a8bc00 100644 --- a/src/Jellyfin.Database/Jellyfin.Database.Implementations/DescendantQueryHelper.cs +++ b/src/Jellyfin.Database/Jellyfin.Database.Implementations/DescendantQueryHelper.cs @@ -49,6 +49,33 @@ public static class DescendantQueryHelper return descendants.AsQueryable(); } + /// + /// Gets all owned descendant IDs for multiple parent items in a single traversal. + /// More efficient than calling per parent because + /// it performs one traversal for all seeds instead of N separate traversals. + /// + /// Database context. + /// Parent item IDs. + /// Set of all owned descendant item IDs (excluding the parent IDs themselves). + public static HashSet GetOwnedDescendantIdsBatch(JellyfinDbContext context, IReadOnlyList parentIds) + { + ArgumentNullException.ThrowIfNull(context); + ArgumentNullException.ThrowIfNull(parentIds); + + if (parentIds.Count == 0) + { + return []; + } + + var seedSet = new HashSet(parentIds); + var descendants = TraverseHierarchyDownOwned(context, seedSet); + + // Remove the seed IDs — callers want only descendants + descendants.ExceptWith(seedSet); + + return descendants; + } + /// /// Gets a queryable of all folder IDs that have any descendant matching the specified criteria. /// Can be used in LINQ .Contains() expressions. -- cgit v1.2.3