mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@40305 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
if ( is_multisite() ) :
|
||||
/**
|
||||
* Test 'site_details' functionality.
|
||||
*
|
||||
* @group ms-site
|
||||
* @group multisite
|
||||
*/
|
||||
class Tests_Multisite_Site_Details extends WP_UnitTestCase {
|
||||
/**
|
||||
* @dataProvider data_whitelisted_options
|
||||
*
|
||||
* @ticket 40063
|
||||
*/
|
||||
public function test_update_whitelisted_option_deletes_site_details_cache( $whitelisted_option, $temporary_value ) {
|
||||
$site = get_site();
|
||||
|
||||
$original_value = $site->$whitelisted_option;
|
||||
update_option( $whitelisted_option, $temporary_value );
|
||||
|
||||
$cached_result = wp_cache_get( $site->id, 'site-details' );
|
||||
|
||||
/* Reset to original value. */
|
||||
update_option( $whitelisted_option, $original_value );
|
||||
|
||||
$this->assertFalse( $cached_result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_whitelisted_options
|
||||
*
|
||||
* @ticket 40063
|
||||
*/
|
||||
public function test_update_whitelisted_option_deletes_blog_details_cache( $whitelisted_option, $temporary_value ) {
|
||||
$blog_details = get_blog_details();
|
||||
|
||||
$original_value = $blog_details->$whitelisted_option;
|
||||
update_option( $whitelisted_option, $temporary_value );
|
||||
|
||||
$cached_result = wp_cache_get( $blog_details->id, 'blog-details' );
|
||||
|
||||
/* Reset to original value. */
|
||||
update_option( $whitelisted_option, $original_value );
|
||||
|
||||
$this->assertFalse( $cached_result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_whitelisted_options
|
||||
*
|
||||
* @ticket 40063
|
||||
*/
|
||||
public function test_update_whitelisted_option_does_not_delete_site_cache( $whitelisted_option, $temporary_value ) {
|
||||
$site = get_site();
|
||||
|
||||
$original_value = $site->$whitelisted_option;
|
||||
update_option( $whitelisted_option, $temporary_value );
|
||||
|
||||
$cached_result = wp_cache_get( $site->id, 'sites' );
|
||||
|
||||
/* Reset to original value. */
|
||||
update_option( $whitelisted_option, $original_value );
|
||||
|
||||
$this->assertNotFalse( $cached_result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_whitelisted_options
|
||||
*
|
||||
* @ticket 40063
|
||||
*/
|
||||
public function test_update_whitelisted_option_does_not_delete_short_blog_details_cache( $whitelisted_option, $temporary_value ) {
|
||||
$blog_details = get_blog_details( null, false );
|
||||
|
||||
$original_value = get_option( $whitelisted_option );
|
||||
update_option( $whitelisted_option, $temporary_value );
|
||||
|
||||
$cached_result = wp_cache_get( $blog_details->id . 'short', 'blog-details' );
|
||||
|
||||
/* Reset to original value. */
|
||||
update_option( $whitelisted_option, $original_value );
|
||||
|
||||
$this->assertNotFalse( $cached_result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_whitelisted_options
|
||||
*
|
||||
* @ticket 40063
|
||||
*/
|
||||
public function test_update_whitelisted_option_does_not_update_sites_last_changed( $whitelisted_option, $temporary_value ) {
|
||||
$last_changed = wp_cache_get_last_changed( 'sites' );
|
||||
|
||||
$original_value = get_option( $whitelisted_option );
|
||||
update_option( $whitelisted_option, $temporary_value );
|
||||
|
||||
$new_last_changed = wp_cache_get_last_changed( 'sites' );
|
||||
|
||||
/* Reset to original value. */
|
||||
update_option( $whitelisted_option, $original_value );
|
||||
|
||||
$this->assertSame( $new_last_changed, $last_changed );
|
||||
}
|
||||
|
||||
public function data_whitelisted_options() {
|
||||
return array(
|
||||
array( 'blogname', 'Custom Site' ),
|
||||
array( 'home', 'http://custom-site-url.org' ),
|
||||
array( 'siteurl', 'http://custom-site-url.org' ),
|
||||
array( 'post_count', '4' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40063
|
||||
*/
|
||||
public function test_update_random_blog_option_does_not_delete_cache() {
|
||||
$site = get_site();
|
||||
|
||||
update_option( 'foobar_option', 'foobar_value' );
|
||||
$cached_result = wp_cache_get( $site->id, 'sites' );
|
||||
|
||||
delete_option( 'foobar_option' );
|
||||
|
||||
$this->assertNotFalse( $cached_result );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
Reference in New Issue
Block a user