Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/7.0] Avoid redundant looping in property metadata #29807

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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