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

WordPress Trac noreply at wordpress.org
Tue May 21 21:36:59 UTC 2024


#61053: Provide a way to load multiple specific network options with a single
database / cache request
---------------------------------------------+-----------------------------
 Reporter:  spacedmonkey                     |       Owner:  spacedmonkey
     Type:  enhancement                      |      Status:  closed
 Priority:  normal                           |   Milestone:  6.6
Component:  Options, Meta APIs               |     Version:  3.0
 Severity:  normal                           |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests commit  |     Focuses:  multisite,
                                             |  performance
---------------------------------------------+-----------------------------
Changes (by spacedmonkey):

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


Comment:

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

 WordPress's `get_network_option` function generally makes individual
 database requests for each network option. While some options are
 preloaded in `wp_load_core_site_options`, many still require single
 database calls to the network options table.

 Building on the work done in [56445], [56990], and [57013], which
 introduced the `wp_prime_option_caches` function, this commit adds two new
 functions: `wp_prime_network_option_caches` and
 `wp_prime_site_option_caches`. These functions enable developers to pass
 an array of option names, allowing caches for these options to be primed
 in a single object cache or database request. If an option is not found,
 the notoptions cache key is refreshed, preventing unnecessary repeated
 requests.

 The function `wp_prime_site_option_caches` is similar to
 `get_site_option`, enabling developers to retrieve network options on the
 current network without needing to know the current network ID. If these
 functions are called in a non-multisite environment, they fall back to
 using wp_prime_option_caches.

 These functions have been implemented in `wp_load_core_site_options`,
 `get_site_transient`, and `set_site_transient`.

 Props to spacedmonkey, peterwilsoncc, mukesh27, joemcgill.
 Fixes #61053.
 }}}

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


More information about the wp-trac mailing list