Make WordPress Core

Changeset 22092


Ignore:
Timestamp:
10/01/2012 06:03:23 PM (12 years ago)
Author:
ryan
Message:
  • Register blog-id-cache group as global
  • Introduce clean_blog_cache() so we can run it independently of refresh_blog_details() which assumes the blog still exists and get_blog_details() can be called.
  • Don't db escape cache keys in get_blog_id_from_url()
  • prepare() the query in get_blog_id_from_url()
  • Return 0 for all failures in get_blog_id_from_url()
  • clean_blog_cache() after dropping tables in wpmu_delete_blog() to make sure the cache is for real cleaned.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/ms.php

    r21823 r22092  
    5656
    5757    $switch = false;
    58     if ( $blog_id != $wpdb->blogid ) {
     58    if ( get_current_blog_id() != $blog_id ) {
    5959        $switch = true;
    6060        switch_to_blog( $blog_id );
    61         $blog = get_blog_details( $blog_id );
    62     } else {
    63         $blog = $GLOBALS['current_blog'];
    64     }
     61    }
     62
     63    $blog = get_blog_details( $blog_id );
    6564
    6665    do_action( 'delete_blog', $blog_id, $drop );
     
    8281
    8382    if ( $drop ) {
    84 
    8583        $drop_tables = apply_filters( 'wpmu_drop_tables', $wpdb->tables( 'blog' ) );
    8684
     
    123121            @rmdir( $dir );
    124122        }
     123
     124        clean_blog_cache( $blog );
    125125    }
    126126
  • trunk/wp-includes/load.php

    r21952 r22092  
    410410
    411411    if ( function_exists( 'wp_cache_add_global_groups' ) ) {
    412         wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
     412        wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache' ) );
    413413        wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
    414414    }
  • trunk/wp-includes/ms-blogs.php

    r22087 r22092  
    254254    $details = get_blog_details( $blog_id, false );
    255255
    256     wp_cache_delete( $blog_id , 'blog-details' );
    257     wp_cache_delete( $blog_id . 'short' , 'blog-details' );
    258     wp_cache_delete( md5( $details->domain . $details->path )  , 'blog-lookup' );
    259     wp_cache_delete( 'current_blog_' . $details->domain, 'site-options' );
    260     wp_cache_delete( 'current_blog_' . $details->domain . $details->path, 'site-options' );
    261     wp_cache_delete( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' );
     256    clean_blog_cache( $details );
    262257
    263258    do_action( 'refresh_blog_details', $blog_id );
     
    315310
    316311    return true;
     312}
     313
     314/**
     315 * Clean the blog cache
     316 *
     317 * @since 3.5.0
     318 *
     319 * @param stdClass $blog The blog details as returned from get_blog_details()
     320 */
     321function clean_blog_cache( $blog ) {
     322    $blog_id = $blog->blog_id;
     323    $domain_path_key = md5( $blog->domain . $blog->path );
     324
     325    wp_cache_delete( $blog_id , 'blog-details' );
     326    wp_cache_delete( $blog_id . 'short' , 'blog-details' );
     327    wp_cache_delete(  $domain_path_key, 'blog-lookup' );
     328    wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' );
     329    wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' );
     330    wp_cache_delete( 'get_id_from_blogname_' . trim( $blog->path, '/' ), 'blog-details' );
     331    wp_cache_delete( $domain_path_key, 'blog-id-cache' );
    317332}
    318333
     
    493508                wp_cache_add_global_groups( $global_groups );
    494509            else
    495                 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
     510                wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', ' blog-id-cache' ) );
    496511            wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
    497512        }
     
    554569                wp_cache_add_global_groups( $global_groups );
    555570            else
    556                 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
     571                wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', ' blog-id-cache' ) );
    557572            wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
    558573        }
  • trunk/wp-includes/ms-functions.php

    r22065 r22092  
    333333 * @param string $domain
    334334 * @param string $path Optional. Not required for subdomain installations.
    335  * @return int
     335 * @return int 0 if no blog found, otherwise the ID of the matching blog
    336336 */
    337337function get_blog_id_from_url( $domain, $path = '/' ) {
    338338    global $wpdb;
    339339
    340     $domain = strtolower( $wpdb->escape( $domain ) );
    341     $path = strtolower( $wpdb->escape( $path ) );
     340    $domain = strtolower( $domain );
     341    $path = strtolower( $path );
    342342    $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );
    343343
    344     if ( $id == -1 ) { // blog does not exist
     344    if ( $id == -1 ) // blog does not exist
    345345        return 0;
    346     } elseif ( $id ) {
    347         return (int)$id;
    348     }
    349 
    350     $id = $wpdb->get_var( "SELECT blog_id FROM $wpdb->blogs WHERE domain = '$domain' and path = '$path' /* get_blog_id_from_url */" );
    351 
    352     if ( !$id ) {
     346    elseif ( $id )
     347        return (int) $id;
     348
     349    $id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s and path = %s /* get_blog_id_from_url */", $domain, $path ) );
     350
     351    if ( ! $id ) {
    353352        wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );
    354         return false;
    355     }
     353        return 0;
     354    }
     355
    356356    wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' );
    357357
Note: See TracChangeset for help on using the changeset viewer.