Make WordPress Core


Ignore:
Timestamp:
02/12/2010 05:06:43 PM (16 years ago)
Author:
ryan
Message:

Preload commonly loaded site options when running multisite without a persistent cache. Introduce wp_cache_reset() and call it instead of wp_cache_init() when re-initing after the blog ID chanages to avoid throwing out the entire cache. Pass cached site options through the site option filter when fetching.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r13056 r13066  
    436436
    437437    return $alloptions;
     438}
     439
     440function wp_load_core_site_options( $site_id = null ) {
     441    global $wpdb, $_wp_using_ext_object_cache;
     442
     443    if ( !is_multisite() || $_wp_using_ext_object_cache || defined( 'WP_INSTALLING' ) )
     444        return;
     445
     446    if ( empty($site_id) )
     447        $site_id = $wpdb->siteid;
     448
     449    $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'dashboard_blog');
     450
     451    $core_options_in = "'" . implode("', '", $core_options) . "'";
     452    $options = $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $site_id) );
     453
     454    foreach ( $options as $option ) {
     455        $key = $option->meta_key;
     456        $cache_key = "{$site_id}:$key";
     457        $option->meta_value = maybe_unserialize( $option->meta_value );
     458
     459        wp_cache_set( $cache_key, $option->meta_value, 'site-options' );
     460    }
    438461}
    439462
     
    33213344        $value = get_option($key, $default);
    33223345    } else {
    3323         $cache_key = "{$wpdb->siteid}:$key";
    3324 
    3325         if ( $use_cache == true && $value = wp_cache_get($cache_key, 'site-options') )
    3326             return $value;
    3327 
    3328         $value = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid) );
    3329 
    3330         if ( is_null($value) )
    3331             $value = $default;
    3332 
    3333         $value = maybe_unserialize( $value );
    3334 
    3335         wp_cache_set( $cache_key, $value, 'site-options' );
     3346        $cache_key = "$wpdb->siteid:$key";
     3347        if ( $use_cache )
     3348            $value = wp_cache_get($cache_key, 'site-options');
     3349
     3350        if ( false === $value ) {
     3351            $value = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid) );
     3352
     3353            if ( is_null($value) )
     3354                $value = $default;
     3355
     3356            $value = maybe_unserialize( $value );
     3357
     3358            wp_cache_set( $cache_key, $value, 'site-options' );
     3359        }
    33363360    }
    33373361
Note: See TracChangeset for help on using the changeset viewer.