diff options
| author | Shadowghost <Ghost_of_Stone@web.de> | 2026-02-05 00:17:44 +0100 |
|---|---|---|
| committer | Shadowghost <Ghost_of_Stone@web.de> | 2026-02-05 01:41:07 +0100 |
| commit | a0346fe5b70a434860f973086be176ecc2018a52 (patch) | |
| tree | 9e005d17c7d7712ccf65527fae7c009ef5d0967c /Jellyfin.Server.Implementations | |
| parent | aedd2b04a2687adfcc52db96aa3fb7b2ad94fdcc (diff) | |
Fix multiple version handling
Diffstat (limited to 'Jellyfin.Server.Implementations')
| -rw-r--r-- | Jellyfin.Server.Implementations/Item/BaseItemRepository.cs | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs index b154592e6e..76769c33e7 100644 --- a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs +++ b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs @@ -1599,10 +1599,35 @@ public sealed class BaseItemRepository } } - // Remove orphaned alternate version links + // Remove orphaned alternate version links and their items if (existingLinkedChildren.Count > 0) { + // Get the child IDs of LocalAlternateVersions that are being removed + // These items should be deleted as they are owned by this video + var orphanedLocalVersionIds = existingLinkedChildren + .Where(e => e.ChildType == DbLinkedChildType.LocalAlternateVersion) + .Select(e => e.ChildId) + .ToList(); + context.LinkedChildren.RemoveRange(existingLinkedChildren); + + // Delete the orphaned LocalAlternateVersion items themselves + if (orphanedLocalVersionIds.Count > 0) + { + var orphanedItems = context.BaseItems + .Where(e => orphanedLocalVersionIds.Contains(e.Id) && e.OwnerId == video.Id) + .ToList(); + + if (orphanedItems.Count > 0) + { + _logger.LogInformation( + "Deleting {Count} orphaned LocalAlternateVersion items for video {VideoName} ({VideoId})", + orphanedItems.Count, + video.Name, + video.Id); + context.BaseItems.RemoveRange(orphanedItems); + } + } } } } @@ -3942,4 +3967,31 @@ public sealed class BaseItemRepository return updated; } + + /// <inheritdoc/> + public void UpsertLinkedChild(Guid parentId, Guid childId, LinkedChildType childType) + { + using var context = _dbProvider.CreateDbContext(); + + var dbChildType = (DbLinkedChildType)childType; + var existingLink = context.LinkedChildren + .FirstOrDefault(lc => lc.ParentId == parentId && lc.ChildId == childId); + + if (existingLink is null) + { + context.LinkedChildren.Add(new LinkedChildEntity + { + ParentId = parentId, + ChildId = childId, + ChildType = dbChildType, + SortOrder = null + }); + } + else + { + existingLink.ChildType = dbChildType; + } + + context.SaveChanges(); + } } |
