Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions uSync.Core/Roots/Configs/SyncConfigMergerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ protected TObject[] GetObjectDifferences<TObject, TKey>(TObject[]? rootObject, T
// keys that are only in the source have been removed from the child, we need to mark them as removed.
foreach (var removedItem in sourceItems.Where(x => targetItems.ContainsKey(x.Key) is false))
{
if (removedItem.Value.ContainsKey(removeProperty))
removedItem.Value[removeProperty] = _removedLabel;

removedItem.Value[removeProperty] = _removedLabel;
targetOnly.Add(removedItem.Value);
}

Expand Down Expand Up @@ -123,18 +121,23 @@ protected TObject[] GetObjectDifferences<TObject, TKey>(TObject[]? rootObject, T
}
}

// removals.
foreach (var targetItem in targetArray)
List<int> removals = [];
for(int i = 0; i < targetArray.Count; i++)
Comment thread
KevinJump marked this conversation as resolved.
{
if (targetItem is not JsonObject targetObject) continue;
if (targetArray[i] is not JsonObject targetObject) continue;
if (targetObject.ContainsKey(removeProperty) is false) continue;

if (targetObject[removeProperty]!.ToString().StartsWith(_removedLabel) is true)
{
// remove it.
targetArray.Remove(targetItem);
// we can't remove it while iterating, so add to a list.
removals.Add(i);
}
}

foreach(var index in removals.OrderDescending())
Comment thread
KevinJump marked this conversation as resolved.
{
targetArray.RemoveAt(index);
}

return targetArray;
}
Expand Down