Fix series merging leaking across libraries and under-counting merged children

This commit is contained in:
Shadowghost
2026-08-21 22:48:47 +02:00
parent 9fa0533506
commit 8e80677bdd
5 changed files with 402 additions and 28 deletions
@@ -39,6 +39,31 @@ public static class DescendantQueryHelper
return descendants.AsQueryable();
}
/// <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).