From 98d7c8d59fa3180e50ee311dfc53164325210896 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Sat, 7 Feb 2026 08:44:42 +0100 Subject: Make sure we deduplicate LinkedChildren --- .../Item/BaseItemRepository.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'Jellyfin.Server.Implementations/Item/BaseItemRepository.cs') diff --git a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs index 20df42583d..3ba6750045 100644 --- a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs +++ b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs @@ -1553,7 +1553,13 @@ public sealed class BaseItemRepository } } - var childIdsToCheck = resolvedChildren.Select(c => c.ChildId).Distinct().ToList(); + // Deduplicate by ChildId, keeping the last occurrence (for playlist ordering) + resolvedChildren = resolvedChildren + .GroupBy(c => c.ChildId) + .Select(g => g.Last()) + .ToList(); + + var childIdsToCheck = resolvedChildren.Select(c => c.ChildId).ToList(); var existingChildIds = childIdsToCheck.Count > 0 ? context.BaseItems .Where(e => childIdsToCheck.Contains(e.Id)) @@ -1646,8 +1652,14 @@ public sealed class BaseItemRepository } } + // Deduplicate by ChildId, keeping the last occurrence + newLinkedChildren = newLinkedChildren + .GroupBy(c => c.ChildId) + .Select(g => g.Last()) + .ToList(); + // Validate that all child items exist - var childIdsToCheck = newLinkedChildren.Select(c => c.ChildId).Distinct().ToList(); + var childIdsToCheck = newLinkedChildren.Select(c => c.ChildId).ToList(); var existingChildIds = childIdsToCheck.Count > 0 ? context.BaseItems .Where(e => childIdsToCheck.Contains(e.Id)) -- cgit v1.2.3