Make WordPress Core

Opened 3 months ago

Closed 7 weeks ago

Last modified 7 weeks ago

#61053 closed enhancement (fixed)

Provide a way to load multiple specific network options with a single database / cache request

Reported by: spacedmonkey's profile spacedmonkey Owned by: spacedmonkey's profile spacedmonkey
Milestone: 6.6 Priority: normal
Severity: normal Version: 3.0
Component: Options, Meta APIs Keywords: has-patch has-unit-tests commit
Focuses: multisite, performance Cc:

Description

There is already a way to prime caches for options in a single request, in the functions wp_prime_option_caches. In WordPress multisite context, there is already wp_load_core_site_options, but that function is designed to run once and is not a developer function. A function should be added to core to allow developers to prime network options caches with a single function call. This function should be used inside of wp_load_core_site_options.

Follow on from #58962 [56445],[56990]

Change History (12)

This ticket was mentioned in PR #6311 on WordPress/wordpress-develop by @spacedmonkey.


3 months ago
#1

  • Keywords has-patch added

Introduced the new function wp_prime_network_option_caches in option.php. This function simplifies the handling of network option caches, enhancing the speed of operations. In the wp_load_core_site_options function, removed cache processing code and replaced it with a call to the new function. These changes improve code efficiency and readability.

Trac ticket: https://core.trac.wordpress.org/ticket/61053

#2 follow-up: @peterwilsoncc
3 months ago

@spacedmonkey I was under the impression that the site options used the meta cache, either directly or indirectly.

If that isn't the case, is there any reason it can't be set up as such?

#3 in reply to: ↑ 2 @spacedmonkey
3 months ago

Replying to peterwilsoncc:

@spacedmonkey I was under the impression that the site options used the meta cache, either directly or indirectly.

If that isn't the case, is there any reason it can't be set up as such?

There is a ticket for converting these functions to use metadata api, see #37181. It was committed in [54080] and then reverted in [54637]. I haven't had a chance loop back on that ticket.

It is unclear to me that loading all network options in memory for every request would be a good thing for performance. Loading in all network transients ( if object cache is not enabled ), might result in megabytes of text or json, might have serious performance issues.

This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.


2 months ago

This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.


8 weeks ago

#6 @spacedmonkey
8 weeks ago

  • Keywords has-unit-tests added
  • Milestone changed from Future Release to 6.6

@spacedmonkey commented on PR #6311:


8 weeks ago
#7

Amazing feedback @peterwilsoncc . It is really appricated. Your best code review! Legend.

#8 @peterwilsoncc
7 weeks ago

  • Keywords commit added
  • Owner set to spacedmonkey
  • Status changed from new to assigned

The linked pull request looks good for commit.

@spacedmonkey I'll assign this to you and let you do the honours, thanks for your patience during the review process.

@spacedmonkey commented on PR #6311:


7 weeks ago
#9

Thanks for the feedback @joemcgill . Actioned feedback.

This ticket was mentioned in Slack in #core-performance by joemcgill. View the logs.


7 weeks ago

#11 @spacedmonkey
7 weeks ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 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.

Note: See TracTickets for help on using tickets.