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

Bypass model validation for rendering models #12999

Merged
merged 1 commit into from
Sep 19, 2022

Conversation

kjac
Copy link
Contributor

@kjac kjac commented Sep 14, 2022

Prerequisites

  • I have added steps to test this contribution in the description below

If there's an existing issue for this PR then this fixes #12579

Description

The slow rendering described in the linked issue is tied to how ASP.NET Core performs validation; specifically validation of object graphs. The more content items exist in near vicinity (parent, children, siblings) of the item being rendered, the larger object graph is traversed.

The only reasonable fix is to disable validation of rendering models, namely models built upon ContentModel or IPublishedContent (ModelsBuilder models).

As this is a behavioral breaking change, we cannot target V10, so the target of this PR is V11.

Testing this fix

The files needed for testing is attached in this ZIP file.

  1. Use the attached DB to get the required content and templates for testing - login with [email protected] / SuperSecret
  2. Copy the attached Razor templates to /views
  3. Use ModelsBuilder mode SourceCodeAuto or SourceCodeManual to generate the Article model (required by the next step)
  4. Include the attached ArticleController in the project
  5. Verify that the five different controller actions render equally fast. The controller actions are triggered by the different templates using route hijacking on the following routes:
    • /articlealtone/ (use the rendering time of this action as benchmark for the rest of the actions)
    • /articlealttwo/
    • /articlealtthree/
    • /articlealtfour/
    • /articlealtfive/
  6. Verify explicitly that model state validation works for non rendering models in the last controller action; supplying a value to the action should make the model state valid:
    image
    image

It is probably a good idea to enable the mini profiler by default when measuring the rendering times:

image

@nikolajlauridsen
Copy link
Contributor

nikolajlauridsen commented Sep 19, 2022

Looks good 👀, tests good 💪

I'll go ahead an merge this even though the acceptance tests are failing, since this is caused by InMemoryAuto being broken

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

Successfully merging this pull request may close these issues.

3 participants