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

[4.x]: Entry field in matrix making entries in the CP very slow. #13904

Closed
johanneshakonsen opened this issue Nov 3, 2023 · 6 comments
Closed

Comments

@johanneshakonsen
Copy link

johanneshakonsen commented Nov 3, 2023

What happened?

Description

I have a project with around 2000 entries, and a "content blocks" matrix field on the entry. The entries use all the blocks to a certain extent, including the ones with entry fields in them. A new entry edit page takes about 200ms to load, there's about 150 database queries and 2000 events according to the Yii debug toolbar.

When I add a matrix block with an entry field, however, the loading time increases to about 6000ms, there's now 4000 database queries and 60000 events. This does not happen when I add a matrix block without an entry field, it also doesn't happen if I introduce a completely new block to the matrix field with only an entry field and add that to the entry. Therefore I am assuming it is related to the fact that many entries are using the matrix blocks with entry fields and that reduces the time they take to render somehow.

Steps to reproduce

  1. Make a section.
  2. Add a matrix field with a block that has an entry field on it
  3. Make 2000 entries and add matrix blocks with entry fields and add entries to them
  4. Make a new entry (observe fast load speeds)
  5. Add matrix block with entry field (observe slow load speeds)

Expected behavior

I am not sure why the amount of entries should matter when rendering the edit-page of an entry in the CP. The expected behaviour would be the same amount of load and similar amounts of db-queries/events happening even if I have a matrix block with an entry added to an entry.

Actual behavior

When I add an entry to a matrix block with an entry field my CP editing experience slows down by about 6 seconds every time I open a new entry or save an existing one.

Craft CMS version

4.5.9

PHP version

8.0.30

Operating system and version

Linux 5.15.68-0-virt

Database type and version

MariaDB 10.4.31

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

None (I disabled them all to test this out)

@brandonkelly
Copy link
Member

Do you have any custom module code or an installed plugin that might be getting involved with those fields?

Simply adding a new Matrix block that contains an Entries field shouldn’t come with any tangible performance impact, no matter how many entries there are, so long as you aren’t actually selecting all 2,000 entries.

@johanneshakonsen
Copy link
Author

Even with every plugin disabled it still slows down from about 150ms to 3.5 seconds.

I've done some more testing, and it seems that the slowdown only triggers if the selected entry also has some entry field on it. It could be that the edit entry page ends up doing a ton of queries because entries in entry field have entries in entry fields that has... and that just keeps going? If so, would it be possible to limit this to query the first child instead the entire tree of relations?

@olivierbon
Copy link
Member

Do you have Validate related entries checked on the Entries field on your block?

@johanneshakonsen
Copy link
Author

johanneshakonsen commented Nov 7, 2023

Yes I did! All over the place actually. Removing "validate related entries" from every entry field fixed my issue. Is this intended behaviour of the feature? That it validates entries all the way down I mean?

A quick test yielded a 15 seconds load time down to <1 second on the live server, so I imagine the client is going to be very happy about this!

@brandonkelly
Copy link
Member

Is this intended behaviour of the feature? That it validates entries all the way down I mean?

It was intended, but clearly a little problematic, and also probably a little confusing, performance aside.

Craft 4.5.10 is out now, which does away with recursive relation validation. “Validate related [type]” settings now only apply when the source element is being saved/validated directly.

@johanneshakonsen
Copy link
Author

Thanks!

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

No branches or pull requests

3 participants