Skip to content

Commit

Permalink
Avoid reduntant looping in property metadata (#29807)
Browse files Browse the repository at this point in the history
Fixes #29642
  • Loading branch information
AndriySvyryd authored Jan 4, 2023
1 parent c70e72a commit c9ee67b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 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,9 @@ 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 +672,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 @@ -693,6 +696,12 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
}
}
}

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

return null;
Expand Down Expand Up @@ -749,6 +758,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 @@ -772,6 +782,12 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
}
}
}

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

return null;
Expand Down

0 comments on commit c9ee67b

Please sign in to comment.