diff options
| author | Shadowghost <Ghost_of_Stone@web.de> | 2026-01-30 21:58:24 +0100 |
|---|---|---|
| committer | Shadowghost <Ghost_of_Stone@web.de> | 2026-01-31 19:21:36 +0100 |
| commit | 694db80d4c8e83ff381af56d2a3dde29e0855c3d (patch) | |
| tree | 4e23899944d4be1389f6f92d3bb98b400bb92a74 /Jellyfin.Server.Implementations/Item | |
| parent | a650148dfd9920986e11d414a71df5b1a7f604e8 (diff) | |
Reroute on version removal
Diffstat (limited to 'Jellyfin.Server.Implementations/Item')
| -rw-r--r-- | Jellyfin.Server.Implementations/Item/BaseItemRepository.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs index 9e6b100b66..22178e57f7 100644 --- a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs +++ b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs @@ -3843,4 +3843,43 @@ public sealed class BaseItemRepository return result; } + + /// <inheritdoc/> + public IReadOnlyList<Guid> GetManualLinkedParentIds(Guid childId) + { + using var context = _dbProvider.CreateDbContext(); + return context.LinkedChildren + .Where(lc => lc.ChildId == childId && lc.ChildType == DbLinkedChildType.Manual) + .Select(lc => lc.ParentId) + .Distinct() + .ToList(); + } + + /// <inheritdoc/> + public int RerouteLinkedChildren(Guid fromChildId, Guid toChildId) + { + using var context = _dbProvider.CreateDbContext(); + + // Get parents that already reference toChildId (to avoid duplicates) + var parentsWithTarget = context.LinkedChildren + .Where(lc => lc.ChildId == toChildId && lc.ChildType == DbLinkedChildType.Manual) + .Select(lc => lc.ParentId) + .ToHashSet(); + + // Update references that won't create duplicates + var updated = context.LinkedChildren + .Where(lc => lc.ChildId == fromChildId + && lc.ChildType == DbLinkedChildType.Manual + && !parentsWithTarget.Contains(lc.ParentId)) + .ExecuteUpdate(s => s.SetProperty(e => e.ChildId, toChildId)); + + // Remove references that would be duplicates + context.LinkedChildren + .Where(lc => lc.ChildId == fromChildId + && lc.ChildType == DbLinkedChildType.Manual + && parentsWithTarget.Contains(lc.ParentId)) + .ExecuteDelete(); + + return updated; + } } |
