Skip to content

Commit c5563e3

Browse files
committed
Avoid reduntant looping in property metadata
Fixes #29642
1 parent bf20e32 commit c5563e3

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/EFCore/Metadata/Internal/Property.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
54
using System.Diagnostics.CodeAnalysis;
65
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
76
using Microsoft.EntityFrameworkCore.Internal;
@@ -28,6 +27,10 @@ public class Property : PropertyBase, IMutableProperty, IConventionProperty, IPr
2827
private ConfigurationSource? _valueGeneratedConfigurationSource;
2928
private ConfigurationSource? _typeMappingConfigurationSource;
3029

30+
private static readonly bool QuirkEnabled29642
31+
= AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue29642", out var enabled) && enabled;
32+
33+
3134
/// <summary>
3235
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
3336
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
@@ -670,6 +673,7 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
670673
var property = this;
671674
for (var i = 0; i < 10000; i++)
672675
{
676+
var currentProperty = property;
673677
foreach (var foreignKey in property.GetContainingForeignKeys())
674678
{
675679
for (var propertyIndex = 0; propertyIndex < foreignKey.Properties.Count; propertyIndex++)
@@ -693,6 +697,12 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
693697
}
694698
}
695699
}
700+
701+
if (!QuirkEnabled29642
702+
&& currentProperty == property)
703+
{
704+
break;
705+
}
696706
}
697707

698708
return null;
@@ -749,6 +759,7 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
749759
var property = this;
750760
for (var i = 0; i < 10000; i++)
751761
{
762+
var currentProperty = property;
752763
foreach (var foreignKey in property.GetContainingForeignKeys())
753764
{
754765
for (var propertyIndex = 0; propertyIndex < foreignKey.Properties.Count; propertyIndex++)
@@ -772,6 +783,12 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
772783
}
773784
}
774785
}
786+
787+
if (!QuirkEnabled29642
788+
&& currentProperty == property)
789+
{
790+
break;
791+
}
775792
}
776793

777794
return null;

0 commit comments

Comments
 (0)