diff options
| author | Shadowghost <Ghost_of_Stone@web.de> | 2026-03-05 22:54:26 +0100 |
|---|---|---|
| committer | Shadowghost <Ghost_of_Stone@web.de> | 2026-03-05 22:54:26 +0100 |
| commit | 744c5539d8471addca131c9d9f7e8c4e30f8c4b5 (patch) | |
| tree | d592731234894c68fc41325795d1a32bace3377c /src | |
| parent | f5b2e0b8f93f6e6ccfd4753caf27b390d6010065 (diff) | |
Fix review comments
Diffstat (limited to 'src')
| -rw-r--r-- | src/Jellyfin.Database/Jellyfin.Database.Implementations/DescendantQueryHelper.cs | 27 |
1 files changed, 27 insertions, 0 deletions
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 @@ -50,6 +50,33 @@ public static class DescendantQueryHelper } /// <summary> + /// Gets all owned descendant IDs for multiple parent items in a single traversal. + /// More efficient than calling <see cref="GetOwnedDescendantIds"/> per parent because + /// it performs one traversal for all seeds instead of N separate traversals. + /// </summary> + /// <param name="context">Database context.</param> + /// <param name="parentIds">Parent item IDs.</param> + /// <returns>Set of all owned descendant item IDs (excluding the parent IDs themselves).</returns> + public static HashSet<Guid> GetOwnedDescendantIdsBatch(JellyfinDbContext context, IReadOnlyList<Guid> parentIds) + { + ArgumentNullException.ThrowIfNull(context); + ArgumentNullException.ThrowIfNull(parentIds); + + if (parentIds.Count == 0) + { + return []; + } + + var seedSet = new HashSet<Guid>(parentIds); + var descendants = TraverseHierarchyDownOwned(context, seedSet); + + // Remove the seed IDs — callers want only descendants + descendants.ExceptWith(seedSet); + + return descendants; + } + + /// <summary> /// Gets a queryable of all folder IDs that have any descendant matching the specified criteria. /// Can be used in LINQ .Contains() expressions. /// </summary> |
