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.
Built from https://develop.svn.wordpress.org/trunk@55854


git-svn-id: http://core.svn.wordpress.org/trunk@55366 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
spacedmonkey 2023-05-24 17:35:18 +00:00
parent f93e6ec4e8
commit 2cd27b2349
3 changed files with 47 additions and 5 deletions

View File

@ -188,7 +188,12 @@ function wp_ajax_wp_compression_test() {
} }
if ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' === ini_get( 'output_handler' ) ) { if ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' === ini_get( 'output_handler' ) ) {
update_site_option( 'can_compress_scripts', 0 ); // Use `update_option()` on single site to mark the option for autoloading.
if ( is_multisite() ) {
update_site_option( 'can_compress_scripts', 0 );
} else {
update_option( 'can_compress_scripts', 0, 'yes' );
}
wp_die( 0 ); wp_die( 0 );
} }
@ -222,10 +227,20 @@ function wp_ajax_wp_compression_test() {
wp_die(); wp_die();
} elseif ( 'no' === $_GET['test'] ) { } elseif ( 'no' === $_GET['test'] ) {
check_ajax_referer( 'update_can_compress_scripts' ); check_ajax_referer( 'update_can_compress_scripts' );
update_site_option( 'can_compress_scripts', 0 ); // Use `update_option()` on single site to mark the option for autoloading.
if ( is_multisite() ) {
update_site_option( 'can_compress_scripts', 0 );
} else {
update_option( 'can_compress_scripts', 0, 'yes' );
}
} elseif ( 'yes' === $_GET['test'] ) { } elseif ( 'yes' === $_GET['test'] ) {
check_ajax_referer( 'update_can_compress_scripts' ); check_ajax_referer( 'update_can_compress_scripts' );
update_site_option( 'can_compress_scripts', 1 ); // Use `update_option()` on single site to mark the option for autoloading.
if ( is_multisite() ) {
update_site_option( 'can_compress_scripts', 1 );
} else {
update_option( 'can_compress_scripts', 1, 'yes' );
}
} }
} }

View File

@ -832,6 +832,10 @@ function upgrade_all() {
upgrade_600(); upgrade_600();
} }
if ( $wp_current_db_version < 55853 ) {
upgrade_630();
}
maybe_disable_link_manager(); maybe_disable_link_manager();
maybe_disable_automattic_widgets(); maybe_disable_automattic_widgets();
@ -2293,6 +2297,29 @@ function upgrade_600() {
} }
} }
/**
* Executes changes made in WordPress 6.3.0.
*
* @ignore
* @since 6.3.0
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_630() {
global $wp_current_db_version;
if ( $wp_current_db_version < 55853 ) {
if ( ! is_multisite() ) {
// Replace non-autoload option can_compress_scripts with autoload option, see #55270
$can_compress_scripts = get_option( 'can_compress_scripts', false );
if ( false !== $can_compress_scripts ) {
delete_option( 'can_compress_scripts' );
add_option( 'can_compress_scripts', $can_compress_scripts, 'yes' );
}
}
}
}
/** /**
* Executes network-level upgrade routines. * Executes network-level upgrade routines.
* *

View File

@ -16,14 +16,14 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.3-alpha-55853'; $wp_version = '6.3-alpha-55854';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
* *
* @global int $wp_db_version * @global int $wp_db_version
*/ */
$wp_db_version = 53496; $wp_db_version = 55853;
/** /**
* Holds the TinyMCE version. * Holds the TinyMCE version.