#37833 closed enhancement (invalid)
To optimize database queries on page load
Reported by: | KaugKo | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Bootstrap/Load | Keywords: | |
Focuses: | performance | Cc: |
Description
I've been optimizing my site SQL Queries on Page Load with Black Box plugins and find out every plugin I used for website have to retrieve their options value on every page load. Sometime there are 3 to 5 get_option() call for each plugins and you can imagine there are more than 30 calls total.
What I am thinking is if Wordpress core advice plugin developers to register their plugin option values with some sort of universal key or prefix example "plugin_abc_setting_1" like db prefix and automatically retrieve all the options value with that prefix and build the global object or array as $theme_options.
If we can do the above way, we will save lots of sql transitions on each page load.
Change History (2)
#1
@
8 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
- Version trunk deleted
#2
@
8 years ago
Hi @pento. Thank for sharing the solution with me. The problem is most of the plugin developers are not using auto load and they just retrieving with multiple
get_option()
and most of the Wordpress sites page load time is always high compare to framework. If Wordpress can encourage the plugin developers to use auto load feature, that would be great.
Anyway, thanks for everything.
Hi @KaugKo, thanks for the suggestion!
There are already several optimisations around loading options - if a plugin creates an option with
add_option()
, and sets the$autoload
parameter to'yes'
, the option will be automatically loaded at the start of every page load, as you suggested.Another optimisation is when there are multiple calls to
get_option()
- if the same option is retrieved twice, the second retrieval won't cause a database query, as the option is already cached.By default, both of these caches are reset at the end of the page load, but there are also plugins that will allow this cache to persist between page loads, removing more load from the MySQL server. You can read more about them here:
https://codex.wordpress.org/Class_Reference/WP_Object_Cache#Persistent_Cache_Plugins