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 8, 2022
1 parent bf20e32 commit e245aa4
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/EFCore/Metadata/Internal/Property.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Internal;
Expand All @@ -28,6 +27,10 @@ public class Property : PropertyBase, IMutableProperty, IConventionProperty, IPr
private ConfigurationSource? _valueGeneratedConfigurationSource;
private ConfigurationSource? _typeMappingConfigurationSource;

private static readonly bool QuirkEnabled29642
= AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue29642", out var enabled) && enabled;


/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand Down Expand Up @@ -670,6 +673,7 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
var property = this;
for (var i = 0; i < 10000; i++)
{
var currentProperty = property;
foreach (var foreignKey in property.GetContainingForeignKeys())
{
for (var propertyIndex = 0; propertyIndex < foreignKey.Properties.Count; propertyIndex++)
Expand All @@ -690,9 +694,17 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
{
return converter;
}

currentProperty = principalProperty;
}
}
}

if (!QuirkEnabled29642
&& currentProperty == property)
{
break;
}
}

return null;
Expand Down Expand Up @@ -749,6 +761,7 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
var property = this;
for (var i = 0; i < 10000; i++)
{
var currentProperty = property;
foreach (var foreignKey in property.GetContainingForeignKeys())
{
for (var propertyIndex = 0; propertyIndex < foreignKey.Properties.Count; propertyIndex++)
Expand All @@ -769,9 +782,17 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
{
return type;
}

currentProperty = principalProperty;
}
}
}

if (!QuirkEnabled29642
&& currentProperty == property)
{
break;
}
}

return null;
Expand Down

0 comments on commit e245aa4

Please sign in to comment.