diff --git a/PARR.AIHITRelationshipsSyncer/Services/Implementations/RelationshipsSyncService.cs b/PARR.AIHITRelationshipsSyncer/Services/Implementations/RelationshipsSyncService.cs index eed168fe..b8d744f9 100644 --- a/PARR.AIHITRelationshipsSyncer/Services/Implementations/RelationshipsSyncService.cs +++ b/PARR.AIHITRelationshipsSyncer/Services/Implementations/RelationshipsSyncService.cs @@ -145,7 +145,7 @@ internal class RelationshipsSyncService : IRelationshipsSyncService List<(string ParentName, string ChildName)> sourcePairs) { var relevantParentNames = sourcePairs.Select(p => p.ParentName).Distinct().ToList(); - + var existingForParents = await _unitRepository.Get() .AsNoTracking() .Include(u => u.ChildUnits).ThenInclude(r => r.ChildUnit) @@ -157,19 +157,19 @@ internal class RelationshipsSyncService : IRelationshipsSyncService Relationship = relationship }) .ToListAsync(); - + var sourceSet = new HashSet<(string, string)>(sourcePairs); var existingSet = new HashSet<(string, string)>( existingForParents.Select(x => (x.ParentName, x.ChildName))); - + var toRemove = existingForParents .Where(r => !sourceSet.Contains((r.ParentName, r.ChildName))) .ToList(); - + var toAdd = sourcePairs .Where(p => !existingSet.Contains(p)) .ToList(); - + _logger.LogInformation("Дельта: удаление {ToRemove}, добавление {ToAdd}", toRemove.Count, toAdd.Count); return (toRemove, toAdd); }