Update saved metadata on primary change

This commit is contained in:
Shadowghost
2026-02-25 21:03:46 +01:00
parent 4bd9dbe910
commit 2d0d497961
6 changed files with 42 additions and 13 deletions

View File

@@ -4439,10 +4439,22 @@ public sealed class BaseItemRepository
}
/// <inheritdoc/>
public int RerouteLinkedChildren(Guid fromChildId, Guid toChildId)
public IReadOnlyList<Guid> RerouteLinkedChildren(Guid fromChildId, Guid toChildId)
{
using var context = _dbProvider.CreateDbContext();
// Collect all affected parent IDs before modifying
var affectedParentIds = context.LinkedChildren
.Where(lc => lc.ChildId == fromChildId && lc.ChildType == DbLinkedChildType.Manual)
.Select(lc => lc.ParentId)
.Distinct()
.ToList();
if (affectedParentIds.Count == 0)
{
return affectedParentIds;
}
// Get parents that already reference toChildId (to avoid duplicates)
var parentsWithTarget = context.LinkedChildren
.Where(lc => lc.ChildId == toChildId && lc.ChildType == DbLinkedChildType.Manual)
@@ -4450,7 +4462,7 @@ public sealed class BaseItemRepository
.ToHashSet();
// Update references that won't create duplicates
var updated = context.LinkedChildren
context.LinkedChildren
.Where(lc => lc.ChildId == fromChildId
&& lc.ChildType == DbLinkedChildType.Manual
&& !parentsWithTarget.Contains(lc.ParentId))
@@ -4463,7 +4475,7 @@ public sealed class BaseItemRepository
&& parentsWithTarget.Contains(lc.ParentId))
.ExecuteDelete();
return updated;
return affectedParentIds;
}
/// <inheritdoc/>