Cache the non-existence of options to prevent redundant queries. props davidhouse. fixes #2268
git-svn-id: http://svn.automattic.com/wordpress/trunk@4798 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ed4186b15f
commit
a741e0d350
|
@ -203,6 +203,10 @@ function is_serialized_string($data) {
|
||||||
function get_option($setting) {
|
function get_option($setting) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
|
// prevent non-existent options from triggering multiple queries
|
||||||
|
if ( true === wp_cache_get($setting, 'notoptions') )
|
||||||
|
return false;
|
||||||
|
|
||||||
$value = wp_cache_get($setting, 'options');
|
$value = wp_cache_get($setting, 'options');
|
||||||
|
|
||||||
if ( false === $value ) {
|
if ( false === $value ) {
|
||||||
|
@ -215,7 +219,8 @@ function get_option($setting) {
|
||||||
if( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
|
if( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
|
||||||
$value = $row->option_value;
|
$value = $row->option_value;
|
||||||
wp_cache_set($setting, $value, 'options');
|
wp_cache_set($setting, $value, 'options');
|
||||||
} else {
|
} else { // option does not exist, so we must cache its non-existence
|
||||||
|
wp_cache_set($setting, true, 'notoptions');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,6 +279,9 @@ function update_option($option_name, $newvalue) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( true === wp_cache_get($option_name, 'notoptions') )
|
||||||
|
wp_cache_delete($option_name, 'notoptions');
|
||||||
|
|
||||||
$_newvalue = $newvalue;
|
$_newvalue = $newvalue;
|
||||||
$newvalue = maybe_serialize($newvalue);
|
$newvalue = maybe_serialize($newvalue);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue