Skip to content

The Free Software Media System - Server Backend & API

Merge remote-tracking branch 'upstream/master' into fix-series-merging

Shadowghoste1af8dce0589
diff --cc src/Jellyfin.Database/Jellyfin.Database.Implementations/DescendantQueryHelper.cs
index 909609e35d,6b08f8dd7e..ac47f00a18
--- a/src/Jellyfin.Database/Jellyfin.Database.Implementations/DescendantQueryHelper.cs
+++ b/src/Jellyfin.Database/Jellyfin.Database.Implementations/DescendantQueryHelper.cs
@@@ -32,38 -32,20 +32,45 @@@ public static class DescendantQueryHelp
{
ArgumentNullException.ThrowIfNull(context);
- var descendants = TraverseHierarchyDown(context, [parentId]);
+ var (closureRoots, linkRoots) = ResolveLinkedRoots(context, parentId);
- descendants.Remove(parentId);
+ var hierarchyDescendants = ClosureDescendants(context, closureRoots);
- return descendants.AsQueryable();
+ var linkedDescendants = context.LinkedChildren
+ .WhereOneOrMany(linkRoots, e => e.ParentId)
+ .Select(e => e.ChildId);
+
+ return hierarchyDescendants
+ .Concat(linkedDescendants)
+ .Where(e => !e.Equals(parentId))
+ .Distinct();
}
+ /// <summary>
+ /// Gets all descendant IDs for multiple parent items in a single traversal.
+ /// Traverses AncestorIds and LinkedChildren, like <see cref="GetAllDescendantIds"/>.
+ /// </summary>
+ /// <param name="context">Database context.</param>
+ /// <param name="parentIds">Parent item IDs.</param>
+ /// <returns>Set of all descendant item IDs (excluding the parent IDs themselves).</returns>
+ public static HashSet<Guid> GetAllDescendantIdsBatch(JellyfinDbContext context, IReadOnlyList<Guid> parentIds)
+ {
+ ArgumentNullException.ThrowIfNull(context);
+ ArgumentNullException.ThrowIfNull(parentIds);
+
+ if (parentIds.Count == 0)
+ {
+ return [];
+ }
+
+ var seedSet = new HashSet<Guid>(parentIds);
+ var descendants = TraverseHierarchyDown(context, seedSet);
+
+ descendants.ExceptWith(seedSet);
+
+ return descendants;
+ }
+
/// <summary>
/// Gets a queryable of all owned descendant IDs for a parent item.
/// Traverses only AncestorIds (hierarchical ownership), NOT LinkedChildren (associations).