AdvancedCustomFields / acf

Advanced Custom Fields
http://advancedcustomfields.com/
823 stars 168 forks source link

ACF calls additional post type and taxonomy database queries on the frontend #829

Closed CreativeDive closed 1 year ago

CreativeDive commented 1 year ago

Hey @mattgrshaw ,

I've noticed there a some new database queries on the frontend called by ACF. It seems this is coming from the brand new ACF post type and taxonomy features. Is that correct?

Bildschirmfoto 2023-05-11 um 13 42 43

I think these queries should not be done on the frontend for performance reasons. Is there a reason why these are not only queried in the backend?

lgladdy commented 1 year ago

All requests to WordPress will need to know about any post types and taxonomies registered, so the queries will happen anytime the WordPress stack is loaded while enabled.

If you disable ACF's post types and taxonomies feature, they shouldn't be executed anymore.

CreativeDive commented 1 year ago

@lgladdy Are these queries only called when we are logged in?

The post type/taxonomy feature is very useful for the most of users. Personally, I've gotten used to doing it myself in code. Therefore I will try to disable it.

CreativeDive commented 1 year ago

yes using:

add_filter( 'acf/settings/enable_post_types', '__return_false' );

... solves that in this case. Thank you @lgladdy

lgladdy commented 1 year ago

@CreativeDive Hey, nah, we'll load regardless of login state as WordPress has to know every single page load about the registered post types.

The database is the standard place to store this for plugins which provide post types and taxonomies. We did experiment with caching to a file, but depending on your host, reading and decoding a file is slower than the database query in many cases so it wasn't worth trying to implement that.

You can find details of how to disable here: https://www.advancedcustomfields.com/resources/acf-settings-enable_post_types/

polevaultweb commented 1 year ago

@CreativeDive appreciate the heads up anyway, glad we could help. Just FYI you don't need to specifically @ any of the team on requests - we monitor this repo as a team 👍