Make WordPress Core

Changeset 55854


Ignore:
Timestamp:
05/24/2023 05:33:26 PM (11 months ago)
Author:
spacedmonkey
Message:

Options, Meta APIs: Change the option can_compress_scripts to be autoloaded.

Ensure that the option can_compress_scripts is autoloaded on single sites, as this option is used in all requests. This change saves one database query per page request.

Props RavanH, spacedmonkey, costdev, azaozz, flixos90.
Fixes #55270.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r55764 r55854  
    189189
    190190    if ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' === ini_get( 'output_handler' ) ) {
    191         update_site_option( 'can_compress_scripts', 0 );
     191        // Use `update_option()` on single site to mark the option for autoloading.
     192        if ( is_multisite() ) {
     193            update_site_option( 'can_compress_scripts', 0 );
     194        } else {
     195            update_option( 'can_compress_scripts', 0, 'yes' );
     196        }
    192197        wp_die( 0 );
    193198    }
     
    223228        } elseif ( 'no' === $_GET['test'] ) {
    224229            check_ajax_referer( 'update_can_compress_scripts' );
    225             update_site_option( 'can_compress_scripts', 0 );
     230            // Use `update_option()` on single site to mark the option for autoloading.
     231            if ( is_multisite() ) {
     232                update_site_option( 'can_compress_scripts', 0 );
     233            } else {
     234                update_option( 'can_compress_scripts', 0, 'yes' );
     235            }
    226236        } elseif ( 'yes' === $_GET['test'] ) {
    227237            check_ajax_referer( 'update_can_compress_scripts' );
    228             update_site_option( 'can_compress_scripts', 1 );
     238            // Use `update_option()` on single site to mark the option for autoloading.
     239            if ( is_multisite() ) {
     240                update_site_option( 'can_compress_scripts', 1 );
     241            } else {
     242                update_option( 'can_compress_scripts', 1, 'yes' );
     243            }
    229244        }
    230245    }
  • trunk/src/wp-admin/includes/upgrade.php

    r55698 r55854  
    833833    }
    834834
     835    if ( $wp_current_db_version < 55853 ) {
     836        upgrade_630();
     837    }
     838
    835839    maybe_disable_link_manager();
    836840
     
    22952299
    22962300/**
     2301 * Executes changes made in WordPress 6.3.0.
     2302 *
     2303 * @ignore
     2304 * @since 6.3.0
     2305 *
     2306 * @global int $wp_current_db_version The old (current) database version.
     2307 */
     2308function upgrade_630() {
     2309    global $wp_current_db_version;
     2310
     2311    if ( $wp_current_db_version < 55853 ) {
     2312        if ( ! is_multisite() ) {
     2313            // Replace non-autoload option can_compress_scripts with autoload option, see #55270
     2314            $can_compress_scripts = get_option( 'can_compress_scripts', false );
     2315            if ( false !== $can_compress_scripts ) {
     2316                delete_option( 'can_compress_scripts' );
     2317                add_option( 'can_compress_scripts', $can_compress_scripts, 'yes' );
     2318            }
     2319        }
     2320    }
     2321}
     2322
     2323/**
    22972324 * Executes network-level upgrade routines.
    22982325 *
  • trunk/src/wp-includes/version.php

    r55505 r55854  
    2424 * @global int $wp_db_version
    2525 */
    26 $wp_db_version = 53496;
     26$wp_db_version = 55853;
    2727
    2828/**
Note: See TracChangeset for help on using the changeset viewer.