From 0503e92bfc894c88c2b23974ef5cd2c700cd25fa Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Fri, 20 Nov 2026 07:25:17 -0500 Subject: Backport pull request #18645 from jellyfin/release-12.z Fix "too many SQL variables" when saving large scan batches and playlists Original-merge: e66161258b926a78be16e0583a3af873fe48305a Merged-by: Bond-009 Backported-by: Cody Robibero --- .../Item/ItemPersistenceService.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Jellyfin.Server.Implementations') diff --git a/Jellyfin.Server.Implementations/Item/ItemPersistenceService.cs b/Jellyfin.Server.Implementations/Item/ItemPersistenceService.cs index 3bf33b969e..4e7e5a5331 100644 --- a/Jellyfin.Server.Implementations/Item/ItemPersistenceService.cs +++ b/Jellyfin.Server.Implementations/Item/ItemPersistenceService.cs @@ -374,7 +374,8 @@ public class ItemPersistenceService : IItemPersistenceService var allListedItemValuesSet = allListedItemValues.ToHashSet(); var existingValues = context.ItemValues - .Where(e => types.Contains(e.Type) && values.Contains(e.Value)) + .WhereOneOrMany(types, e => e.Type) + .WhereOneOrMany(values, e => e.Value) .AsEnumerable() .Where(e => allListedItemValuesSet.Contains((e.Type, e.Value))) .ToArray(); @@ -428,7 +429,7 @@ public class ItemPersistenceService : IItemPersistenceService var allExistingAncestorIds = itemsWithAncestors.Count > 0 ? context.AncestorIds - .Where(e => itemsWithAncestors.Contains(e.ItemId)) + .WhereOneOrMany(itemsWithAncestors, e => e.ItemId) .ToList() .GroupBy(e => e.ItemId) .ToDictionary(g => g.Key, g => g.ToList()) @@ -442,7 +443,7 @@ public class ItemPersistenceService : IItemPersistenceService var validAncestorIdsSet = allRequestedAncestorIds.Count > 0 ? context.BaseItems - .Where(e => allRequestedAncestorIds.Contains(e.Id)) + .WhereOneOrMany(allRequestedAncestorIds, e => e.Id) .Select(f => f.Id) .ToHashSet() : new HashSet(); @@ -502,7 +503,7 @@ public class ItemPersistenceService : IItemPersistenceService { var allParentIds = folderIds.Concat(videoIds).Distinct().ToList(); var allLinkedChildren = context.LinkedChildren - .Where(e => allParentIds.Contains(e.ParentId)) + .WhereOneOrMany(allParentIds, e => e.ParentId) .ToList(); allLinkedChildrenByParent = allLinkedChildren @@ -572,7 +573,7 @@ public class ItemPersistenceService : IItemPersistenceService var pathToIdMap = pathsToResolve.Count > 0 ? context.BaseItems - .Where(e => e.Path != null && pathsToResolve.Contains(e.Path)) + .WhereOneOrMany(pathsToResolve, e => e.Path!) .Select(e => new { e.Path, e.Id }) .GroupBy(e => e.Path!) .ToDictionary(g => g.Key, g => g.First().Id) -- cgit v1.2.3