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

Avoid redundant looping in property metadata #29805

Merged
merged 1 commit into from
Dec 16, 2022
Merged

Avoid redundant looping in property metadata #29805

merged 1 commit into from
Dec 16, 2022

Conversation

AndriySvyryd
Copy link
Member

Fixes #29642

@@ -858,29 +858,37 @@ private void Create(IEntityType entityType, CSharpRuntimeAnnotationCodeGenerator
var principalProperty = property;
for (var i = 0; i < 10000; i++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 10,000 really the appropriate number here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be the length of the longest FK chain allowable in the model

@ajcvickers
Copy link
Member

Can you say a bit more about what is happening here? What are the situations where the 10,000 limit will be hit? Also, which tests cover these cases?

@roji roji changed the title Avoid reduntant looping in property metadata Avoid redundant looping in property metadata Dec 9, 2022
@AndriySvyryd
Copy link
Member Author

The code is traversing FKs. The 10000 limit will be hit if there's an FK cycle in the model. These models are invalid and will fail validation, but the current code runs before validation, so it shouldn't fail before validation runs.

Tests:

public virtual void Detects_relationship_cycle()

public virtual void Detects_shared_table_root_cycle()

@ajcvickers
Copy link
Member

ajcvickers commented Dec 12, 2022

The customer report didn't fail in validation. I get this was likely a bug, but it makes me nervous that we still have a very high limit such that some other bug could cause very slow model building without failing in validation. Should we not just fail early when we exhaust the loop, rather than assuming model validation will fail?

@AndriySvyryd
Copy link
Member Author

Should we not just fail early when we exhaust the loop, rather than assuming model validation will fail?

Sure, but only in main

@ajcvickers
Copy link
Member

Only in main seems reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performance regression in model building in Entity Framework Core 7
2 participants