[wp-trac] [WordPress Trac] #58962: Provide a way to load multiple specific options with a single database request

WordPress Trac noreply at wordpress.org
Thu Aug 24 14:40:17 UTC 2023


#58962: Provide a way to load multiple specific options with a single database
request
--------------------------------------+--------------------------
 Reporter:  flixos90                  |       Owner:  flixos90
     Type:  enhancement               |      Status:  closed
 Priority:  normal                    |   Milestone:  6.4
Component:  Options, Meta APIs        |     Version:
 Severity:  normal                    |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests  |     Focuses:  performance
--------------------------------------+--------------------------
Changes (by flixos90):

 * status:  assigned => closed
 * resolution:   => fixed


Comment:

 In [changeset:"56445" 56445]:
 {{{
 #!CommitTicketReference repository="" revision="56445"
 Options, Meta APIs: Introduce `prime_options()` to load multiple options
 with a single database request.

 WordPress's `get_option()` function generally relies on making individual
 database requests for each option, however with the majority of options
 (in most cases) being autoloaded, i.e. fetched once with a single database
 request and then stored in (memory) cache.

 As part of a greater effort to reduce the amount of options that are
 unnecessarily autoloaded, this changeset introduces an alternative way to
 retrieve multiple options in a performant manner, with a single database
 request. This provides a reasonable alternative for e.g. plugins that use
 several options which only need to be loaded in a few specific screens.

 Specifically, this changeset introduces the following functions:
 * `prime_options( $options )` is the foundation to load multiple specific
 options with a single database request. Only options that aren't already
 cached (in `alloptions` or an individual cache) are retrieved from the
 database.
 * `prime_options_by_group( $option_group )` is a convenience wrapper
 function for the above which allows to prime all options of a specific
 option group (as configured via `register_setting()`).
 * `get_options( $options )` is another wrapper function which first primes
 the requested options and then returns them in an associative array,
 calling `get_option()` for each of them.

 Props mukesh27, joemcgill, costdev, olliejones.
 Fixes #58962.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58962#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list