Make WordPress Core

Changeset 25043


Ignore:
Timestamp:
08/16/2013 10:41:23 PM (12 years ago)
Author:
duck_
Message:

Introduce a notoptions cache for site options.

Props wonderboymusic. Fixes #19008.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/option.php

    r24760 r25043  
    768768        return $pre;
    769769
     770    // prevent non-existent options from triggering multiple queries
     771    $notoptions = wp_cache_get( 'notoptions', 'site-options' );
     772    if ( isset( $notoptions[$option] ) )
     773        return apply_filters( 'default_site_option_' . $option, $default );
     774
    770775    if ( ! is_multisite() ) {
    771776        $default = apply_filters( 'default_site_option_' . $option, $default );
     
    785790                wp_cache_set( $cache_key, $value, 'site-options' );
    786791            } else {
     792                $notoptions[$option] = true;
     793                wp_cache_set( 'notoptions', $notoptions, 'site-options' );
    787794                $value = apply_filters( 'default_site_option_' . $option, $default );
    788795            }
     
    814821    global $wpdb;
    815822
     823    wp_protect_special_option( $option );
     824
    816825    $value = apply_filters( 'pre_add_site_option_' . $option, $value );
    817826
     
    821830        $cache_key = "{$wpdb->siteid}:$option";
    822831
    823         if ( false !== get_site_option( $option ) )
    824             return false;
     832        // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
     833        $notoptions = wp_cache_get( 'notoptions', 'site-options' );
     834        if ( ! is_array( $notoptions ) || ! isset( $notoptions[$option] ) )
     835            if ( false !== get_site_option( $option ) )
     836                return false;
    825837
    826838        $value = sanitize_option( $option, $value );
     839
    827840        wp_cache_set( $cache_key, $value, 'site-options' );
    828841
     
    831844        $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $value ) );
    832845        $value = $_value;
     846
     847        // This option exists now
     848        $notoptions = wp_cache_get( 'notoptions', 'site-options' ); // yes, again... we need it to be fresh
     849        if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
     850            unset( $notoptions[$option] );
     851            wp_cache_set( 'notoptions', $notoptions, 'site-options' );
     852        }
    833853    }
    834854
     
    902922    global $wpdb;
    903923
     924    wp_protect_special_option( $option );
     925
    904926    $oldvalue = get_site_option( $option );
    905927    $value = apply_filters( 'pre_update_site_option_' . $option, $value, $oldvalue );
     
    910932    if ( false === $oldvalue )
    911933        return add_site_option( $option, $value );
     934
     935    $notoptions = wp_cache_get( 'notoptions', 'site-options' );
     936    if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
     937        unset( $notoptions[$option] );
     938        wp_cache_set( 'notoptions', $notoptions, 'site-options' );
     939    }
    912940
    913941    if ( !is_multisite() ) {
Note: See TracChangeset for help on using the changeset viewer.