From cde61269235ba33355cc96b8eaff2a0164aee3c0 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Sun, 19 Mar 2017 16:22:45 +0000 Subject: [PATCH] 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 --- wp-includes/ms-blogs.php | 20 ++++++++++++++++++-- wp-includes/ms-default-filters.php | 9 +++++---- wp-includes/version.php | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index 9188750386..1c22e424d6 100644 --- a/wp-includes/ms-blogs.php +++ b/wp-includes/ms-blogs.php @@ -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; } diff --git a/wp-includes/ms-default-filters.php b/wp-includes/ms-default-filters.php index 08d752a34d..011a71259a 100644 --- a/wp-includes/ms-default-filters.php +++ b/wp-includes/ms-default-filters.php @@ -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' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 381322e933..8ac59b9ea3 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.