Changeset 4855
- Timestamp:
- 02/01/2007 08:53:08 AM (18 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/cache.php
r4686 r4855 192 192 $this->cache['category'][$catt->cat_ID] = $catt; 193 193 } 194 } else 195 if ('options' == $group) { 196 $wpdb->hide_errors(); 197 if (!$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'")) { 198 $options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options"); 199 } 200 $wpdb->show_errors(); 201 202 if ( ! $options ) 203 return; 204 205 foreach ($options as $option) { 206 $this->cache['options'][$option->option_name] = $option->option_value; 207 } 208 } 194 } 195 209 196 } 210 197 -
trunk/wp-includes/functions.php
r4842 r4855 209 209 return $pre; 210 210 211 $value = wp_cache_get($setting, 'options'); 212 213 if ( false === $value ) { 214 if ( defined('WP_INSTALLING') ) 215 $wpdb->hide_errors(); 216 $row = $wpdb->get_row("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1"); 217 if ( defined('WP_INSTALLING') ) 218 $wpdb->show_errors(); 219 220 if( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values 221 $value = $row->option_value; 222 wp_cache_set($setting, $value, 'options'); 223 } else { 224 return false; 211 // prevent non-existent options from triggering multiple queries 212 $notoptions = wp_cache_get('notoptions', 'options'); 213 if ( isset($notoptions[$setting]) ) 214 return false; 215 216 $alloptions = wp_load_alloptions(); 217 218 if ( isset($alloptions[$setting]) ) { 219 $value = $alloptions[$setting]; 220 } else { 221 $value = wp_cache_get($setting, 'options'); 222 223 if ( false === $value ) { 224 if ( defined('WP_INSTALLING') ) 225 $wpdb->hide_errors(); 226 $row = $wpdb->get_row("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1"); 227 if ( defined('WP_INSTALLING') ) 228 $wpdb->show_errors(); 229 230 if( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values 231 $value = $row->option_value; 232 wp_cache_set($setting, $value, 'options'); 233 } else { // option does not exist, so we must cache its non-existence 234 $notoptions[$setting] = true; 235 wp_cache_set('notoptions', $notoptions, 'options'); 236 return false; 237 } 225 238 } 226 239 } … … 234 247 235 248 return apply_filters( 'option_' . $setting, maybe_unserialize($value) ); 249 } 250 251 function wp_protect_special_option($option) { 252 $protected = array('alloptions', 'notoptions'); 253 if ( in_array($option, $protected) ) 254 die(sprintf(__('%s is a protected WP option and may not be modified'), wp_specialchars($option))); 236 255 } 237 256 … … 263 282 } 264 283 284 function wp_load_alloptions() { 285 global $wpdb; 286 287 $alloptions = wp_cache_get('alloptions', 'options'); 288 289 if ( !$alloptions ) { 290 $wpdb->hide_errors(); 291 if ( !$alloptions_db = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'") ) 292 $alloptions_db = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options"); 293 $wpdb->show_errors(); 294 $alloptions = array(); 295 foreach ( (array) $alloptions_db as $o ) 296 $alloptions[$o->option_name] = $o->option_value; 297 wp_cache_set('alloptions', $alloptions, 'options'); 298 } 299 return $alloptions; 300 } 301 265 302 function update_option($option_name, $newvalue) { 266 303 global $wpdb; 304 305 wp_protect_special_option($option_name); 267 306 268 307 if ( is_string($newvalue) ) … … 280 319 } 281 320 321 $notoptions = wp_cache_get('notoptions', 'options'); 322 if ( isset($notoptions[$option_name]) ) { 323 unset($notoptions[$option_name]); 324 wp_cache_set('notoptions', $notoptions, 'options'); 325 } 326 282 327 $_newvalue = $newvalue; 283 328 $newvalue = maybe_serialize($newvalue); 284 329 285 wp_cache_set($option_name, $newvalue, 'options'); 330 $alloptions = wp_load_alloptions(); 331 if ( isset($alloptions[$option_name]) ) { 332 $alloptions[$options_name] = $newvalue; 333 wp_cache_set('alloptions', $alloptions, 'options'); 334 } else { 335 wp_cache_set($option_name, $newvalue, 'options'); 336 } 286 337 287 338 $newvalue = $wpdb->escape($newvalue); … … 299 350 global $wpdb; 300 351 301 // Make sure the option doesn't already exist 302 if ( false !== get_option($name) ) 303 return; 352 wp_protect_special_option($name); 353 354 // Make sure the option doesn't already exist we can check the cache before we ask for a db query 355 $notoptions = wp_cache_get('notoptions', 'options'); 356 if ( isset($notoptions[$name]) ) { 357 unset($notoptions[$name]); 358 wp_cache_set('notoptions', $notoptions, 'options'); 359 } elseif ( false !== get_option($name) ) { 360 return; 361 } 304 362 305 363 $value = maybe_serialize($value); 306 364 307 wp_cache_set($name, $value, 'options'); 365 if ( 'yes' == $autoload ) { 366 $alloptions = wp_load_alloptions(); 367 $alloptions[$name] = $value; 368 wp_cache_set('alloptions', $alloptions, 'options'); 369 } else { 370 wp_cache_set($name, $value, 'options'); 371 } 308 372 309 373 $name = $wpdb->escape($name); … … 317 381 function delete_option($name) { 318 382 global $wpdb; 383 384 wp_protect_special_option($name); 385 319 386 // Get the ID, if no ID then return 320 $option _id = $wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = '$name'");321 if ( !$option _id ) return false;387 $option = $wpdb->get_row("SELECT option_id, autoload FROM $wpdb->options WHERE option_name = '$name'"); 388 if ( !$option->option_id ) return false; 322 389 $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'"); 323 wp_cache_delete($name, 'options'); 390 if ( 'yes' == $option->autoload ) { 391 $alloptions = wp_load_alloptions(); 392 if ( isset($alloptions[$name]) ) { 393 unset($alloptions[$name]); 394 wp_cache_set('alloptions', $alloptions, 'options'); 395 } 396 } else { 397 wp_cache_delete($name, 'options'); 398 } 324 399 return true; 325 400 } -
trunk/wp-includes/version.php
r4832 r4855 4 4 5 5 $wp_version = '2.2-bleeding'; 6 $wp_db_version = 477 2;6 $wp_db_version = 4773; 7 7 8 8 ?>
Note: See TracChangeset
for help on using the changeset viewer.