Multisite: Handle sites cache invalidation more granularly for option updates.

Previously `update_blog_option()` would trigger an invalidation of that site's entire cache although these changes did not affect the content of these caches. Furthermore changes to the special options `blogname`, `siteurl` and `post_count` should not invalidate the entire cache of that site, but only their respective site details cache. The option `home` now has the same behavior as it also belongs to the site details, but did not invalidate the cache at all previously.

Several new unit tests confirm these changes work as expected.

Fixes #40063.

Built from https://develop.svn.wordpress.org/trunk@40305


git-svn-id: http://core.svn.wordpress.org/trunk@40212 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Felix Arntz 2017-03-19 16:22:45 +00:00
parent e69b9b244c
commit cde6126923
3 changed files with 24 additions and 7 deletions

View File

@ -472,6 +472,24 @@ function clean_blog_cache( $blog ) {
wp_cache_set( 'last_changed', microtime(), 'sites' );
}
/**
* Cleans the site details cache for a site.
*
* @since 4.7.4
* @private
*
* @param int $site_id Optional. Site ID. Default is the current site ID.
*/
function _clean_site_details_cache( $site_id = 0 ) {
$site_id = (int) $site_id;
if ( ! $site_id ) {
$site_id = get_current_blog_id();
}
wp_cache_delete( $site_id, 'site-details' );
wp_cache_delete( $site_id, 'blog-details' );
}
/**
* Retrieves site data given a site ID or site object.
*
@ -736,8 +754,6 @@ function update_blog_option( $id, $option, $value, $deprecated = null ) {
$return = update_option( $option, $value );
restore_current_blog();
refresh_blog_details( $id );
return $return;
}

View File

@ -84,10 +84,11 @@ add_filter( 'force_filtered_html_on_import', '__return_true' );
remove_filter( 'option_siteurl', '_config_wp_siteurl' );
remove_filter( 'option_home', '_config_wp_home' );
// Some options changes should trigger blog details refresh.
add_action( 'update_option_blogname', 'refresh_blog_details', 10, 0 );
add_action( 'update_option_siteurl', 'refresh_blog_details', 10, 0 );
add_action( 'update_option_post_count', 'refresh_blog_details', 10, 0 );
// Some options changes should trigger site details refresh.
add_action( 'update_option_blogname', '_clean_site_details_cache', 10, 0 );
add_action( 'update_option_siteurl', '_clean_site_details_cache', 10, 0 );
add_action( 'update_option_post_count', '_clean_site_details_cache', 10, 0 );
add_action( 'update_option_home', '_clean_site_details_cache', 10, 0 );
// If the network upgrade hasn't run yet, assume ms-files.php rewriting is used.
add_filter( 'default_site_option_ms_files_rewriting', '__return_true' );

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.8-alpha-40304';
$wp_version = '4.8-alpha-40305';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.