WordPress.org

Make WordPress Core

Changeset 4524


Ignore:
Timestamp:
11/23/2006 08:39:39 PM (12 years ago)
Author:
ryan
Message:

Key caches by blog ID for those doing the multi blog trick.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-db.php

    r4495 r4524  
    482482        $wpdb->query("UPDATE $wpdb->categories SET link_count = '$count' WHERE cat_ID = '$cat_id'");
    483483        wp_cache_delete($cat_id, 'category');
    484     }
     484        do_action('edit_category', $cat_id);
     485    }
     486
     487    do_action('edit_link', $link_ID);
    485488}   // wp_set_link_cats()
    486489
  • trunk/wp-includes/category-template.php

    r4495 r4524  
    6161
    6262function get_the_category($id = false) {
    63 global $post, $category_cache;
     63global $post, $category_cache, $blog_id;
    6464
    6565    if ( !$id )
    6666        $id = $post->ID;
    6767
    68     if ( !isset($category_cache[$id]) )
     68    if ( !isset($category_cache[$blog_id][$id]) )
    6969        update_post_category_cache($id);
    7070
    71     $categories = $category_cache[$id];
     71    $categories = $category_cache[$blog_id][$id];
    7272
    7373    if ( !empty($categories) )
     
    141141
    142142function in_category($category) { // Check if the current post is in the given category
    143     global $category_cache, $post;
    144 
    145     if ( isset( $category_cache[$post->ID][$category] ) )
     143    global $category_cache, $post, $blog_id;
     144
     145    if ( isset( $category_cache[$blog_id][$post->ID][$category] ) )
    146146        return true;
    147147    else
  • trunk/wp-includes/functions.php

    r4517 r4524  
    107107
    108108function get_lastpostdate($timezone = 'server') {
    109     global $cache_lastpostdate, $pagenow, $wpdb;
     109    global $cache_lastpostdate, $pagenow, $wpdb, $blog_id;
    110110    $add_seconds_blog = get_option('gmt_offset') * 3600;
    111111    $add_seconds_server = date('Z');
    112     if ( !isset($cache_lastpostdate[$timezone]) ) {
     112    if ( !isset($cache_lastpostdate[$blog_id][$timezone]) ) {
    113113        switch(strtolower($timezone)) {
    114114            case 'gmt':
     
    122122                break;
    123123        }
    124         $cache_lastpostdate[$timezone] = $lastpostdate;
    125     } else {
    126         $lastpostdate = $cache_lastpostdate[$timezone];
     124        $cache_lastpostdate[$blog_id][$timezone] = $lastpostdate;
     125    } else {
     126        $lastpostdate = $cache_lastpostdate[$blog_id][$timezone];
    127127    }
    128128    return $lastpostdate;
     
    130130
    131131function get_lastpostmodified($timezone = 'server') {
    132     global $cache_lastpostmodified, $pagenow, $wpdb;
     132    global $cache_lastpostmodified, $pagenow, $wpdb, $blog_id;
    133133    $add_seconds_blog = get_option('gmt_offset') * 3600;
    134134    $add_seconds_server = date('Z');
    135     if ( !isset($cache_lastpostmodified[$timezone]) ) {
     135    if ( !isset($cache_lastpostmodified[$blog_id][$timezone]) ) {
    136136        switch(strtolower($timezone)) {
    137137            case 'gmt':
     
    149149            $lastpostmodified = $lastpostdate;
    150150        }
    151         $cache_lastpostmodified[$timezone] = $lastpostmodified;
    152     } else {
    153         $lastpostmodified = $cache_lastpostmodified[$timezone];
     151        $cache_lastpostmodified[$blog_id][$timezone] = $lastpostmodified;
     152    } else {
     153        $lastpostmodified = $cache_lastpostmodified[$blog_id][$timezone];
    154154    }
    155155    return $lastpostmodified;
     
    509509
    510510function update_post_cache(&$posts) {
    511     global $post_cache;
     511    global $post_cache, $blog_id;
    512512
    513513    if ( !$posts )
     
    515515
    516516    for ($i = 0; $i < count($posts); $i++) {
    517         $post_cache[$posts[$i]->ID] = &$posts[$i];
     517        $post_cache[$blog_id][$posts[$i]->ID] = &$posts[$i];
    518518    }
    519519}
    520520
    521521function clean_post_cache($id) {
    522     global $post_cache;
    523 
    524     if ( isset( $post_cache[$id] ) )
    525         unset( $post_cache[$id] );
     522    global $post_cache, $blog_id;
     523
     524    if ( isset( $post_cache[$blog_id][$id] ) )
     525        unset( $post_cache[$blog_id][$id] );
    526526}
    527527
    528528function update_page_cache(&$pages) {
    529     global $page_cache;
     529    global $page_cache, $blog_id;
    530530
    531531    if ( !$pages )
     
    533533
    534534    for ($i = 0; $i < count($pages); $i++) {
    535         $page_cache[$pages[$i]->ID] = &$pages[$i];
     535        $page_cache[$blog_id][$pages[$i]->ID] = &$pages[$i];
    536536        wp_cache_add($pages[$i]->ID, $pages[$i], 'pages');
    537537    }
     
    540540
    541541function clean_page_cache($id) {
    542     global $page_cache;
    543 
    544     if ( isset( $page_cache[$id] ) )
    545         unset( $page_cache[$id] );
     542    global $page_cache, $blog_id;
     543
     544    if ( isset( $page_cache[$blog_id][$id] ) )
     545        unset( $page_cache[$blog_id][$id] );
    546546}
    547547
     
    579579function update_post_caches(&$posts) {
    580580    global $post_cache, $category_cache, $post_meta_cache;
    581     global $wpdb;
     581    global $wpdb, $blog_id;
    582582
    583583    // No point in doing all this work if we didn't match any posts.
     
    588588    for ($i = 0; $i < count($posts); $i++) {
    589589        $post_id_array[] = $posts[$i]->ID;
    590         $post_cache[$posts[$i]->ID] = &$posts[$i];
     590        $post_cache[$blog_id][$posts[$i]->ID] = &$posts[$i];
    591591    }
    592592
     
    599599
    600600function update_postmeta_cache($post_id_list = '') {
    601     global $wpdb, $post_meta_cache;
     601    global $wpdb, $post_meta_cache, $blog_id;
    602602
    603603    // We should validate this comma-separated list for the upcoming SQL query
     
    627627        // Change from flat structure to hierarchical:
    628628        if ( !isset($post_meta_cache) )
    629             $post_meta_cache = array();
     629            $post_meta_cache[$blog_id] = array();
    630630
    631631        foreach ($meta_list as $metarow) {
     
    635635
    636636            // Force subkeys to be array type:
    637             if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) )
    638                 $post_meta_cache[$mpid] = array();
    639             if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) )
    640                 $post_meta_cache[$mpid]["$mkey"] = array();
     637            if ( !isset($post_meta_cache[$blog_id][$mpid]) || !is_array($post_meta_cache[$blog_id][$mpid]) )
     638                $post_meta_cache[$blog_id][$mpid] = array();
     639            if ( !isset($post_meta_cache[$blog_id][$mpid]["$mkey"]) || !is_array($post_meta_cache[$blog_id][$mpid]["$mkey"]) )
     640                $post_meta_cache[$blog_id][$mpid]["$mkey"] = array();
    641641
    642642            // Add a value to the current pid/key:
    643             $post_meta_cache[$mpid][$mkey][] = $mval;
     643            $post_meta_cache[$blog_id][$mpid][$mkey][] = $mval;
    644644        }
    645645    }
  • trunk/wp-includes/post.php

    r4521 r4524  
    1010
    1111function &get_children($args = '', $output = OBJECT) {
    12     global $post_cache, $wpdb;
     12    global $post_cache, $wpdb, $blog_id;
    1313
    1414    if ( empty($args) ) {
     
    3333    if ( $children ) {
    3434        foreach ( $children as $key => $child ) {
    35             $post_cache[$child->ID] =& $children[$key];
     35            $post_cache[$blog_id][$child->ID] =& $children[$key];
    3636            $kids[$child->ID] =& $children[$key];
    3737        }
     
    7575// Handles post caching.
    7676function &get_post(&$post, $output = OBJECT) {
    77     global $post_cache, $wpdb;
     77    global $post_cache, $wpdb, $blog_id;
    7878
    7979    if ( empty($post) ) {
     
    8585        if ( 'page' == $post->post_type )
    8686            return get_page($post, $output);
    87         if ( !isset($post_cache[$post->ID]) )
    88             $post_cache[$post->ID] = &$post;
    89         $_post = & $post_cache[$post->ID];
     87        if ( !isset($post_cache[$blog_id][$post->ID]) )
     88            $post_cache[$blog_id][$post->ID] = &$post;
     89        $_post = & $post_cache[$blog_id][$post->ID];
    9090    } else {
    9191        if ( $_post = wp_cache_get($post, 'pages') )
    9292            return get_page($_post, $output);
    93         elseif ( isset($post_cache[$post]) )
    94             $_post = & $post_cache[$post];
     93        elseif ( isset($post_cache[$blog_id][$post]) )
     94            $_post = & $post_cache[$blog_id][$post];
    9595        else {
    9696            $query = "SELECT * FROM $wpdb->posts WHERE ID = '$post' LIMIT 1";
     
    9898            if ( 'page' == $_post->post_type )
    9999                return get_page($_post, $output);
    100             $post_cache[$post] = & $_post;
     100            $post_cache[$blog_id][$post] = & $_post;
    101101        }
    102102    }
    103103
    104104    if ( defined('WP_IMPORTING') )
    105         unset($post_cache);
     105        unset($post_cache[$blog_id]);
    106106
    107107    if ( $output == OBJECT ) {
     
    242242
    243243function add_post_meta($post_id, $key, $value, $unique = false) {
    244     global $wpdb, $post_meta_cache;
     244    global $wpdb, $post_meta_cache, $blog_id;
    245245
    246246    $post_id = (int) $post_id;
     
    252252    }
    253253
    254     $post_meta_cache[$post_id][$key][] = $value;
     254    $post_meta_cache[$blog_id][$post_id][$key][] = $value;
    255255
    256256    $value = maybe_serialize($value);
     
    263263
    264264function delete_post_meta($post_id, $key, $value = '') {
    265     global $wpdb, $post_meta_cache;
     265    global $wpdb, $post_meta_cache, $blog_id;
    266266
    267267    $post_id = (int) $post_id;
     
    278278    if ( empty($value) ) {
    279279        $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key'");
    280         unset($post_meta_cache[$post_id][$key]);
     280        unset($post_meta_cache[$blog_id][$post_id][$key]);
    281281    } else {
    282282        $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key' AND meta_value = '$value'");
    283         $cache_key = $post_meta_cache[$post_id][$key];
     283        $cache_key = $post_meta_cache[$blog_id][$post_id][$key];
    284284        if ($cache_key) foreach ( $cache_key as $index => $data )
    285285            if ( $data == $value )
    286                 unset($post_meta_cache[$post_id][$key][$index]);
    287     }
    288 
    289     unset($post_meta_cache[$post_id][$key]);
     286                unset($post_meta_cache[$blog_id][$post_id][$key][$index]);
     287    }
     288
     289    unset($post_meta_cache[$blog_id][$post_id][$key]);
    290290
    291291    return true;
     
    293293
    294294function get_post_meta($post_id, $key, $single = false) {
    295     global $wpdb, $post_meta_cache;
     295    global $wpdb, $post_meta_cache, $blog_id;
    296296
    297297    $post_id = (int) $post_id;
    298298
    299     if ( !isset($post_meta_cache[$post_id]) )
     299    if ( isset($post_meta_cache[$blog_id][$post_id][$key]) ) {
     300        if ( $single ) {
     301            return maybe_unserialize( $post_meta_cache[$blog_id][$post_id][$key][0] );
     302        } else {
     303            return maybe_unserialize( $post_meta_cache[$blog_id][$post_id][$key] );
     304        }
     305    }
     306
     307    if ( !isset($post_meta_cache[$blog_id][$post_id]) )
    300308        update_postmeta_cache($post_id);
    301309
    302310    if ( $single ) {
    303         if ( isset($post_meta_cache[$post_id][$key][0]) )
    304             return maybe_unserialize($post_meta_cache[$post_id][$key][0]);
     311        if ( isset($post_meta_cache[$blog_id][$post_id][$key][0]) )
     312            return maybe_unserialize($post_meta_cache[$blog_id][$post_id][$key][0]);
    305313        else
    306314            return '';
    307315    }   else {
    308         return maybe_unserialize($post_meta_cache[$post_id][$key]);
     316        return maybe_unserialize($post_meta_cache[$blog_id][$post_id][$key]);
    309317    }
    310318}
    311319
    312320function update_post_meta($post_id, $key, $value, $prev_value = '') {
    313     global $wpdb, $post_meta_cache;
     321    global $wpdb, $post_meta_cache, $blog_id;
    314322
    315323    $post_id = (int) $post_id;
     
    329337    if ( empty($prev_value) ) {
    330338        $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE meta_key = '$key' AND post_id = '$post_id'");
    331         $cache_key = $post_meta_cache[$post_id][$key];
     339        $cache_key = $post_meta_cache[$blog_id][$post_id][$key];
    332340        if ( !empty($cache_key) )
    333341            foreach ($cache_key as $index => $data)
    334                 $post_meta_cache[$post_id][$key][$index] = $original_value;
     342                $post_meta_cache[$blog_id][$post_id][$key][$index] = $original_value;
    335343    } else {
    336344        $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE meta_key = '$key' AND post_id = '$post_id' AND meta_value = '$prev_value'");
    337         $cache_key = $post_meta_cache[$post_id][$key];
     345        $cache_key = $post_meta_cache[$blog_id][$post_id][$key];
    338346        if ( !empty($cache_key) )
    339347            foreach ($cache_key as $index => $data)
    340348                if ( $data == $original_prev )
    341                     $post_meta_cache[$post_id][$key][$index] = $original_value;
     349                    $post_meta_cache[$blog_id][$post_id][$key][$index] = $original_value;
    342350    }
    343351
     
    347355
    348356function get_post_custom($post_id = 0) {
    349     global $id, $post_meta_cache, $wpdb;
     357    global $id, $post_meta_cache, $wpdb, $blog_id;
    350358
    351359    if ( !$post_id )
     
    354362    $post_id = (int) $post_id;
    355363
    356     if ( !isset($post_meta_cache[$post_id]) )
     364    if ( !isset($post_meta_cache[$blog_id][$post_id]) )
    357365        update_postmeta_cache($post_id);
    358366
    359     return $post_meta_cache[$post_id];
     367    return $post_meta_cache[$blog_id][$post_id];
    360368}
    361369
     
    797805        $wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'");
    798806        wp_cache_delete($cat_id, 'category');
    799     }
     807        do_action('edit_category', $cat_id);
     808    }
     809
     810    do_action('edit_post', $post_ID);
    800811}   // wp_set_post_categories()
    801812
     
    896907// Handles page caching.
    897908function &get_page(&$page, $output = OBJECT) {
    898     global $wpdb;
     909    global $wpdb, $blog_id;
    899910
    900911    if ( empty($page) ) {
     
    914925            $_page = & $GLOBALS['page'];
    915926            wp_cache_add($_page->ID, $_page, 'pages');
    916         } elseif ( !isset($_page) && $_page == $GLOBALS['post_cache'][$page] ) {
     927        } elseif ( !isset($_page) && $_page == $GLOBALS['post_cache'][$blog_id][$page] ) {
    917928            return get_post($page, $output);
    918929        } elseif ( isset($_page) && $_page == wp_cache_get($page, 'pages') ) {
     
    980991
    981992function &get_page_children($page_id, $pages) {
    982     global $page_cache;
     993    global $page_cache, $blog_id;
    983994
    984995    if ( empty($pages) )
    985         $pages = &$page_cache;
     996        $pages = &$page_cache[$blog_id];
    986997
    987998    $page_list = array();
Note: See TracChangeset for help on using the changeset viewer.