Make WordPress Core

Ticket #10274: 10274.diff

File 10274.diff, 9.7 KB (added by ryan, 16 years ago)

Untested and incomplete and possibly crackheaded

  • wp-includes/functions.php

     
    331331        if ( isset( $notoptions[$setting] ) )
    332332                return $default;
    333333
    334         $alloptions = wp_load_alloptions();
     334        $value = wp_cache_get( $setting, 'options' );
    335335
    336         if ( isset( $alloptions[$setting] ) ) {
    337                 $value = $alloptions[$setting];
    338         } else {
    339                 $value = wp_cache_get( $setting, 'options' );
     336        if ( false === $value ) {
     337                if ( defined( 'WP_INSTALLING' ) )
     338                        $suppress = $wpdb->suppress_errors();
     339                // expected_slashed ($setting)
     340                $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1" );
     341                if ( defined( 'WP_INSTALLING' ) )
     342                        $wpdb->suppress_errors($suppress);
    340343
    341                 if ( false === $value ) {
    342                         if ( defined( 'WP_INSTALLING' ) )
    343                                 $suppress = $wpdb->suppress_errors();
    344                         // expected_slashed ($setting)
    345                         $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1" );
    346                         if ( defined( 'WP_INSTALLING' ) )
    347                                 $wpdb->suppress_errors($suppress);
    348 
    349                         if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
    350                                 $value = $row->option_value;
    351                                 wp_cache_add( $setting, $value, 'options' );
    352                         } else { // option does not exist, so we must cache its non-existence
    353                                 $notoptions[$setting] = true;
    354                                 wp_cache_set( 'notoptions', $notoptions, 'options' );
    355                                 return $default;
    356                         }
     344                if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
     345                        $value = $row->option_value;
     346                        wp_cache_add( $setting, $value, 'options' );
     347                        wp_cache_delete( 'all_options', 'options' );
     348                } else { // option does not exist, so we must cache its non-existence
     349                        $notoptions[$setting] = true;
     350                        wp_cache_set( 'notoptions', $notoptions, 'options' );
     351                        return $default;
    357352                }
    358353        }
    359354
     
    400395}
    401396
    402397/**
    403  * Retrieve all autoload options or all options, if no autoloaded ones exist.
    404  *
    405  * This is different from wp_load_alloptions() in that this function does not
    406  * cache its results and will retrieve all options from the database every time
    407  *
    408  * it is called.
    409  *
    410  * @since 1.0.0
    411  * @package WordPress
    412  * @subpackage Option
    413  * @uses apply_filters() Calls 'pre_option_$optionname' hook with option value as parameter.
    414  * @uses apply_filters() Calls 'all_options' on options list.
    415  *
    416  * @return array List of all options.
    417  */
    418 function get_alloptions() {
    419         global $wpdb;
    420         $show = $wpdb->hide_errors();
    421         if ( !$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
    422                 $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
    423         $wpdb->show_errors($show);
    424 
    425         foreach ( (array) $options as $option ) {
    426                 // "When trying to design a foolproof system,
    427                 //  never underestimate the ingenuity of the fools :)" -- Dougal
    428                 if ( in_array( $option->option_name, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) )
    429                         $option->option_value = untrailingslashit( $option->option_value );
    430                 $value = maybe_unserialize( $option->option_value );
    431                 $all_options->{$option->option_name} = apply_filters( 'pre_option_' . $option->option_name, $value );
    432         }
    433         return apply_filters( 'all_options', $all_options );
    434 }
    435 
    436 /**
    437  * Loads and caches all autoloaded options, if available or all options.
    438  *
    439  * This is different from get_alloptions(), in that this function will cache the
    440  * options and will return the cached options when called again.
    441  *
    442  * @since 2.2.0
    443  * @package WordPress
    444  * @subpackage Option
    445  *
    446  * @return array List all options.
    447  */
    448 function wp_load_alloptions() {
    449         global $wpdb;
    450 
    451         $alloptions = wp_cache_get( 'alloptions', 'options' );
    452 
    453         if ( !$alloptions ) {
    454                 $suppress = $wpdb->suppress_errors();
    455                 if ( !$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
    456                         $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
    457                 $wpdb->suppress_errors($suppress);
    458                 $alloptions = array();
    459                 foreach ( (array) $alloptions_db as $o )
    460                         $alloptions[$o->option_name] = $o->option_value;
    461                 wp_cache_add( 'alloptions', $alloptions, 'options' );
    462         }
    463         return $alloptions;
    464 }
    465 
    466 /**
    467398 * Update the value of an option that was already added.
    468399 *
    469400 * You do not need to serialize values, if the value needs to be serialize, then
     
    522453        $_newvalue = $newvalue;
    523454        $newvalue = maybe_serialize( $newvalue );
    524455
    525         $alloptions = wp_load_alloptions();
    526         if ( isset( $alloptions[$option_name] ) ) {
    527                 $alloptions[$option_name] = $newvalue;
    528                 wp_cache_set( 'alloptions', $alloptions, 'options' );
    529         } else {
    530                 wp_cache_set( $option_name, $newvalue, 'options' );
    531         }
     456        wp_cache_set( $option_name, $newvalue, 'options' );
     457        wp_cache_delete( 'all_options', 'options' );
    532458
    533459        $wpdb->update($wpdb->options, array('option_value' => $newvalue), array('option_name' => $option_name) );
    534460
     
    583509        $value = maybe_serialize( $value );
    584510        $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
    585511
    586         if ( 'yes' == $autoload ) {
    587                 $alloptions = wp_load_alloptions();
    588                 $alloptions[$name] = $value;
    589                 wp_cache_set( 'alloptions', $alloptions, 'options' );
    590         } else {
    591                 wp_cache_set( $name, $value, 'options' );
    592         }
     512        wp_cache_set( $name, $value, 'options' );
     513        wp_cache_delete( 'all_options', 'options');
    593514
    594515        // This option exists now
    595516        $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh
     
    626547                return false;
    627548        // expected_slashed ($name)
    628549        $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );
    629         if ( 'yes' == $option->autoload ) {
    630                 $alloptions = wp_load_alloptions();
    631                 if ( isset( $alloptions[$name] ) ) {
    632                         unset( $alloptions[$name] );
    633                         wp_cache_set( 'alloptions', $alloptions, 'options' );
    634                 }
    635         } else {
    636                 wp_cache_delete( $name, 'options' );
    637         }
     550        wp_cache_delete( $name, 'options' );
     551        wp_cache_delete( 'all_options', 'options' );
     552
    638553        return true;
    639554}
    640555
     
    683598                $value = wp_cache_get($transient, 'transient');
    684599        } else {
    685600                $transient_option = '_transient_' . $wpdb->escape($transient);
    686                 // If option is not in alloptions, it is not autoloaded and thus has a timeout
    687                 $alloptions = wp_load_alloptions();
    688                 if ( !isset( $alloptions[$transient_option] ) ) {
    689                         $transient_timeout = '_transient_timeout_' . $wpdb->escape($transient);
    690                         if ( get_option($transient_timeout) < time() ) {
     601                $transient_timeout = '_transient_timeout_' . $wpdb->escape($transient);
     602                // TODO: Avoid timeout option request if option is autoloaded,
     603                // autoloaded options don't have timeouts.
     604                $timeout = get_option($transient_timeout);
     605                if ( $timeout ) {
     606                        if ( $timeout < time() ) {
    691607                                delete_option($transient_option);
    692608                                delete_option($transient_timeout);
    693609                                return false;
     
    17601676                return true;
    17611677
    17621678        $suppress = $wpdb->suppress_errors();
    1763         $alloptions = wp_load_alloptions();
    17641679        // If siteurl is not set to autoload, check it specifically
    1765         if ( !isset( $alloptions['siteurl'] ) )
     1680        if ( !wp_cache_get('siteurl', 'options') )
    17661681                $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );
    17671682        else
    1768                 $installed = $alloptions['siteurl'];
     1683                $installed = wp_cache_get('siteurl', 'options');
    17691684        $wpdb->suppress_errors( $suppress );
    17701685
    17711686        $installed = !empty( $installed );
  • wp-includes/formatting.php

     
    241241                $quote_style = ENT_QUOTES;
    242242        }
    243243
    244         // Store the site charset as a static to avoid multiple calls to wp_load_alloptions()
     244        // Store the site charset as a static to avoid multiple calls to wp_cache_get()
    245245        if ( !$charset ) {
    246246                static $_charset;
    247247                if ( !isset( $_charset ) ) {
    248                         $alloptions = wp_load_alloptions();
    249                         $_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : '';
     248                        $_charset = wp_cache_get('blog_charset');
    250249                }
    251250                $charset = $_charset;
    252251        }
  • wp-settings.php

     
    302302        wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
    303303}
    304304
     305/**
     306 * Loads and caches all autoloaded options
     307 *
     308 * @since 2.2.0
     309 * @package WordPress
     310 * @subpackage Option
     311 *
     312 */
     313function wp_load_alloptions() {
     314        global $wpdb;
     315
     316        if ( !defined( 'WP_INSTALLING' ) ) {
     317                error_log('fetchin all_option');
     318                $all_options = wp_cache_get('all_options', 'options');
     319
     320                if ( false !== $all_options ) {
     321                        if ( false !== wp_cache_get_multi( array('options' => $all_options) ) )
     322                                return;
     323                }
     324        }
     325
     326        $suppress = $wpdb->suppress_errors();
     327        // order by option_id asc in case there are duplicate values - this makes the most recent value overwrite the others in the array
     328        //  TODO: Assumes there are no autoload options, need to make this assumption optional
     329        $all_options_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options FORCE INDEX(PRIMARY) ORDER BY option_id ASC" );
     330        $wpdb->suppress_errors($suppress);
     331        $options = array();
     332        foreach ( (array) $all_options_db as $o ) {
     333                wp_cache_add($o->option_name, $o->option_value, 'options');
     334                $options[] = $o->option_name;
     335        }
     336
     337        wp_cache_set('all_options', $options, 'options');
     338
     339        return;
     340}
     341
     342wp_load_alloptions();
     343
    305344require (ABSPATH . WPINC . '/plugin.php');
    306345require (ABSPATH . WPINC . '/default-filters.php');
    307346include_once(ABSPATH . WPINC . '/pomo/mo.php');