Make WordPress Core

Changeset 56061


Ignore:
Timestamp:
06/27/2023 10:39:55 AM (18 months ago)
Author:
spacedmonkey
Message:

Options, Meta APIs: Prime network options in a single cache call using wp_cache_get_multiple.

Tweak the wp_load_core_site_options function, to also prime network options using wp_cache_get_multiple if persistent object cache is present.

Props mukesh27, oglekler, peterwilsoncc, costdev, jeremyfelt, spacedmonkey.
Fixes #56913.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/option.php

    r55884 r56061  
    362362
    363363/**
    364  * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.
     364 * Loads and primes caches of certain often requested network options if is_multisite().
    365365 *
    366366 * @since 3.0.0
     367 * @since 6.3.0 Also prime caches for network options when persistent object cache is enabled.
    367368 *
    368369 * @global wpdb $wpdb WordPress database abstraction object.
    369370 *
    370  * @param int $network_id Optional site ID for which to query the options. Defaults to the current site.
     371 * @param int $network_id Optional. Network ID of network for which to prime network options cache. Defaults to current network.
    371372 */
    372373function wp_load_core_site_options( $network_id = null ) {
    373374    global $wpdb;
    374375
    375     if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) {
     376    if ( ! is_multisite() || wp_installing() ) {
    376377        return;
    377378    }
     
    382383
    383384    $core_options = array( 'site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting' );
     385
     386    if ( wp_using_ext_object_cache() ) {
     387        $cache_keys = array();
     388        foreach ( $core_options as $option ) {
     389            $cache_keys[] = "{$network_id}:{$option}";
     390        }
     391        wp_cache_get_multiple( $cache_keys, 'site-options' );
     392
     393        return;
     394    }
    384395
    385396    $core_options_in = "'" . implode( "', '", $core_options ) . "'";
Note: See TracChangeset for help on using the changeset viewer.