Skip to content

Commit

Permalink
Avoid reduntant looping in property metadata
Browse files Browse the repository at this point in the history
Fixes #29642
  • Loading branch information
AndriySvyryd committed Dec 12, 2022
1 parent 4a2118f commit 1f12a1e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -858,29 +858,37 @@ private void Create(
var principalProperty = property;
for (var i = 0; i < 10000; i++)
{
IProperty? nextProperty = null;
foreach (var foreignKey in principalProperty.GetContainingForeignKeys())
{
for (var propertyIndex = 0; propertyIndex < foreignKey.Properties.Count; propertyIndex++)
{
if (principalProperty == foreignKey.Properties[propertyIndex])
{
var newPrincipalProperty = foreignKey.PrincipalKey.Properties[propertyIndex];
if (property == principalProperty
if (newPrincipalProperty == property
|| newPrincipalProperty == principalProperty)
{
break;
}

principalProperty = newPrincipalProperty;

type = (Type?)principalProperty[CoreAnnotationNames.ValueConverterType];
type = (Type?)newPrincipalProperty[CoreAnnotationNames.ValueConverterType];
if (type != null)
{
return type;
}

nextProperty = newPrincipalProperty;
}
}
}

if (nextProperty == null)
{
break;
}

principalProperty = nextProperty;
}

return null;
Expand Down
28 changes: 22 additions & 6 deletions src/EFCore/Metadata/Internal/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
var property = this;
for (var i = 0; i < 10000; i++)
{
Property? nextProperty = null;
foreach (var foreignKey in property.GetContainingForeignKeys())
{
for (var propertyIndex = 0; propertyIndex < foreignKey.Properties.Count; propertyIndex++)
Expand All @@ -683,16 +684,23 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
break;
}

property = principalProperty;

converter = (ValueConverter?)property[CoreAnnotationNames.ValueConverter];
converter = (ValueConverter?)principalProperty[CoreAnnotationNames.ValueConverter];
if (converter != null)
{
return converter;
}

nextProperty = principalProperty;
}
}
}

if (nextProperty == null)
{
break;
}

property = nextProperty;
}

return null;
Expand Down Expand Up @@ -749,6 +757,7 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
var property = this;
for (var i = 0; i < 10000; i++)
{
Property? nextProperty = null;
foreach (var foreignKey in property.GetContainingForeignKeys())
{
for (var propertyIndex = 0; propertyIndex < foreignKey.Properties.Count; propertyIndex++)
Expand All @@ -762,16 +771,23 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
break;
}

property = principalProperty;

type = (Type?)property[CoreAnnotationNames.ProviderClrType];
type = (Type?)principalProperty[CoreAnnotationNames.ProviderClrType];
if (type != null)
{
return type;
}

nextProperty = principalProperty;
}
}
}

if (nextProperty == null)
{
break;
}

property = nextProperty;
}

return null;
Expand Down

0 comments on commit 1f12a1e

Please sign in to comment.