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]: customField $contentService->setFieldContext ignored? #13992

Closed
aloco opened this issue Dec 5, 2023 · 4 comments
Closed

[4.x]: customField $contentService->setFieldContext ignored? #13992

aloco opened this issue Dec 5, 2023 · 4 comments

Comments

@aloco
Copy link

aloco commented Dec 5, 2023

What happened?

Description

We have a rather big install with some big formie forms, therefore a lot of custom fields in the table (1622). When making any web request, there is a call to customFields https://github.com/craftcms/cms/blob/4.5/src/elements/db/ElementQuery.php#L2110-L2119
which takes almost half a second to return and consumes a lot of CPU. The result contains all custom fields, including formie and matrix related custom fields. I ruled out that the query is slow, but was wondering, because the query, doesn´t filter global which is set as fieldContext. Is this what it should do? This happens on frontend requests and also in CP, no matter which page. As far as I understand from the callstack, this is initiated by checking the current User

Currently our site is relative slow because of that - do you know how to work around that issue besides not using big formie forms adding a lot of custom fields?

Screenshot 2023-12-05 at 15 03 08 Screenshot 2023-12-05 at 15 06 53

Steps to reproduce

  1. Create a lot of custom fields (>1500)
  2. Check response time in profiler

Expected behavior

Load only required custom fields, less CPU usage

Actual behavior

Long response times and excessive CPU usage

Craft CMS version

4.5.11.1

PHP version

8.1.21

Operating system and version

Linux 5.15.107+

Database type and version

MariaDB 10.5.23

Image driver and version

Imagick 3.7.0 (ImageMagick 7.1.0-50)

Installed plugins and versions

  • Formie 2.0.42
@brandonkelly
Copy link
Member

It’s expected that all fields are queried up front, however it wasn’t necessary to be actually instantiating all of them right away.

I’ve just made a change so fields are only instantiated the first time they are actually needed for something. Until then they only will exist as the raw config data pulled from the database, which should speed things up for you.

If you’d like to test it before the next release, you can change your craftcms/cms requirement in composer.json to dev-develop as 4.5.11.1, and run composer update.

@aloco
Copy link
Author

aloco commented Dec 11, 2023

Hi,

thank you! This helped!

@brandonkelly
Copy link
Member

Thanks for testing :)

@brandonkelly
Copy link
Member

Craft 4.5.12 is out with that change!

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

2 participants