Skip to content

Commit edc4ec3

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

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/EFCore/Metadata/Internal/Property.cs

Lines changed: 17 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,9 @@ 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+
3133
/// <summary>
3234
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
3335
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
@@ -670,6 +672,7 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
670672
var property = this;
671673
for (var i = 0; i < 10000; i++)
672674
{
675+
var currentProperty = property;
673676
foreach (var foreignKey in property.GetContainingForeignKeys())
674677
{
675678
for (var propertyIndex = 0; propertyIndex < foreignKey.Properties.Count; propertyIndex++)
@@ -693,6 +696,12 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
693696
}
694697
}
695698
}
699+
700+
if (!QuirkEnabled29642
701+
&& currentProperty == property)
702+
{
703+
break;
704+
}
696705
}
697706

698707
return null;
@@ -749,6 +758,7 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
749758
var property = this;
750759
for (var i = 0; i < 10000; i++)
751760
{
761+
var currentProperty = property;
752762
foreach (var foreignKey in property.GetContainingForeignKeys())
753763
{
754764
for (var propertyIndex = 0; propertyIndex < foreignKey.Properties.Count; propertyIndex++)
@@ -772,6 +782,12 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
772782
}
773783
}
774784
}
785+
786+
if (!QuirkEnabled29642
787+
&& currentProperty == property)
788+
{
789+
break;
790+
}
775791
}
776792

777793
return null;

0 commit comments

Comments
 (0)