Prefix the notoptions
cache key in the multisite site-options
group with $wpdb->siteid
to avoid collisions and race conditions when using a fancy multi-network setup. Adds unit test.
Fixes #25883. git-svn-id: https://develop.svn.wordpress.org/trunk@26304 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
731d102afb
commit
36a5af537e
@ -757,7 +757,8 @@ function get_site_option( $option, $default = false, $use_cache = true ) {
|
|||||||
return $pre;
|
return $pre;
|
||||||
|
|
||||||
// prevent non-existent options from triggering multiple queries
|
// prevent non-existent options from triggering multiple queries
|
||||||
$notoptions = wp_cache_get( 'notoptions', 'site-options' );
|
$notoptions_key = "{$wpdb->siteid}:notoptions";
|
||||||
|
$notoptions = wp_cache_get( $notoptions_key, 'site-options' );
|
||||||
if ( isset( $notoptions[$option] ) )
|
if ( isset( $notoptions[$option] ) )
|
||||||
return apply_filters( 'default_site_option_' . $option, $default );
|
return apply_filters( 'default_site_option_' . $option, $default );
|
||||||
|
|
||||||
@ -779,7 +780,7 @@ function get_site_option( $option, $default = false, $use_cache = true ) {
|
|||||||
wp_cache_set( $cache_key, $value, 'site-options' );
|
wp_cache_set( $cache_key, $value, 'site-options' );
|
||||||
} else {
|
} else {
|
||||||
$notoptions[$option] = true;
|
$notoptions[$option] = true;
|
||||||
wp_cache_set( 'notoptions', $notoptions, 'site-options' );
|
wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
|
||||||
$value = apply_filters( 'default_site_option_' . $option, $default );
|
$value = apply_filters( 'default_site_option_' . $option, $default );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -812,6 +813,7 @@ function add_site_option( $option, $value ) {
|
|||||||
wp_protect_special_option( $option );
|
wp_protect_special_option( $option );
|
||||||
|
|
||||||
$value = apply_filters( 'pre_add_site_option_' . $option, $value );
|
$value = apply_filters( 'pre_add_site_option_' . $option, $value );
|
||||||
|
$notoptions_key = "{$wpdb->siteid}:notoptions";
|
||||||
|
|
||||||
if ( !is_multisite() ) {
|
if ( !is_multisite() ) {
|
||||||
$result = add_option( $option, $value );
|
$result = add_option( $option, $value );
|
||||||
@ -819,7 +821,7 @@ function add_site_option( $option, $value ) {
|
|||||||
$cache_key = "{$wpdb->siteid}:$option";
|
$cache_key = "{$wpdb->siteid}:$option";
|
||||||
|
|
||||||
// Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
|
// Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
|
||||||
$notoptions = wp_cache_get( 'notoptions', 'site-options' );
|
$notoptions = wp_cache_get( $notoptions_key, 'site-options' );
|
||||||
if ( ! is_array( $notoptions ) || ! isset( $notoptions[$option] ) )
|
if ( ! is_array( $notoptions ) || ! isset( $notoptions[$option] ) )
|
||||||
if ( false !== get_site_option( $option ) )
|
if ( false !== get_site_option( $option ) )
|
||||||
return false;
|
return false;
|
||||||
@ -835,10 +837,10 @@ function add_site_option( $option, $value ) {
|
|||||||
wp_cache_set( $cache_key, $value, 'site-options' );
|
wp_cache_set( $cache_key, $value, 'site-options' );
|
||||||
|
|
||||||
// This option exists now
|
// This option exists now
|
||||||
$notoptions = wp_cache_get( 'notoptions', 'site-options' ); // yes, again... we need it to be fresh
|
$notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // yes, again... we need it to be fresh
|
||||||
if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
|
if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
|
||||||
unset( $notoptions[$option] );
|
unset( $notoptions[$option] );
|
||||||
wp_cache_set( 'notoptions', $notoptions, 'site-options' );
|
wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -922,10 +924,11 @@ function update_site_option( $option, $value ) {
|
|||||||
if ( false === $old_value )
|
if ( false === $old_value )
|
||||||
return add_site_option( $option, $value );
|
return add_site_option( $option, $value );
|
||||||
|
|
||||||
$notoptions = wp_cache_get( 'notoptions', 'site-options' );
|
$notoptions_key = "{$wpdb->siteid}:notoptions";
|
||||||
|
$notoptions = wp_cache_get( $notoptions_key, 'site-options' );
|
||||||
if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
|
if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
|
||||||
unset( $notoptions[$option] );
|
unset( $notoptions[$option] );
|
||||||
wp_cache_set( 'notoptions', $notoptions, 'site-options' );
|
wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !is_multisite() ) {
|
if ( !is_multisite() ) {
|
||||||
|
@ -90,4 +90,24 @@ class Tests_Option_SiteOption extends WP_UnitTestCase {
|
|||||||
$this->assertEquals( get_site_option( $option, $default ), $default );
|
$this->assertEquals( get_site_option( $option, $default ), $default );
|
||||||
$this->assertFalse( get_site_option( $option ) );
|
$this->assertFalse( get_site_option( $option ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group multisite
|
||||||
|
*/
|
||||||
|
function test_site_notoptions() {
|
||||||
|
global $wpdb;
|
||||||
|
$notoptions_key = "{$wpdb->siteid}:notoptions";
|
||||||
|
|
||||||
|
$_notoptions = wp_cache_get( 'notoptions', 'site-options' );
|
||||||
|
$this->assertEmpty( $_notoptions );
|
||||||
|
$_notoptions1 = wp_cache_get( $notoptions_key, 'site-options' );
|
||||||
|
$this->assertEmpty( $_notoptions1 );
|
||||||
|
|
||||||
|
get_site_option( 'burrito' );
|
||||||
|
|
||||||
|
$notoptions = wp_cache_get( 'notoptions', 'site-options' );
|
||||||
|
$this->assertEmpty( $notoptions );
|
||||||
|
$notoptions1 = wp_cache_get( $notoptions_key, 'site-options' );
|
||||||
|
$this->assertNotEmpty( $notoptions1 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user