Make WordPress Core


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.