Skip to content

Commit

Permalink
remove redundant parent lookup when parent guid is empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Sep 25, 2023
1 parent 9801bee commit e532323
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions uSync.Core/Serialization/Serializers/ContentSerializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,26 +341,33 @@ protected virtual IEnumerable<uSyncChange> DeserializeBase(TObject item, XElemen
var parentNode = info.Element(uSyncConstants.Xml.Parent);
if (parentNode != null && parentNode.Attribute(uSyncConstants.Xml.Key).ValueOrDefault(Guid.Empty) != Guid.Empty)
{
var parent = FindParent(parentNode, false);
if (parent == null)
if (parentNode.GetKey() == Guid.Empty)
{
var friendlyPath = info.Element(uSyncConstants.Xml.Path).ValueOrDefault(string.Empty);
if (!string.IsNullOrWhiteSpace(friendlyPath))
{
logger.LogDebug("Find Parent failed, will search by path {FriendlyPath}", friendlyPath);
parent = FindParentByPath(friendlyPath);
}
}

if (parent != null)
{
parentId = parent.Id;
nodePath = CalculateNodePath(item, parent);
nodeLevel = CalculateNodeLevel(item, parent);
logger.LogDebug("Parent is root (-1)");
}
else
{
logger.LogDebug("Unable to find parent but parent node is set in configuration");
var parent = FindParent(parentNode, false);
if (parent == null)
{
var friendlyPath = info.Element(uSyncConstants.Xml.Path).ValueOrDefault(string.Empty);
if (!string.IsNullOrWhiteSpace(friendlyPath))
{
logger.LogDebug("Find Parent failed, will search by path {FriendlyPath}", friendlyPath);
parent = FindParentByPath(friendlyPath);
}
}

if (parent != null)
{
parentId = parent.Id;
nodePath = CalculateNodePath(item, parent);
nodeLevel = CalculateNodeLevel(item, parent);
}
else
{
logger.LogDebug("Unable to find parent but parent node is set in configuration");
}
}
}

Expand Down

0 comments on commit e532323

Please sign in to comment.