Changeset 4517

Show
Ignore:
Timestamp:
11/23/06 15:38:22 (2 years ago)
Author:
matt
Message:

This makes things a little more interesting and cacheable (sp?)

Files:

Legend:

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

    r4513 r4517  
    547547 
    548548function update_post_category_cache($post_ids) { 
    549     global $wpdb, $category_cache
     549    global $wpdb, $category_cache, $blog_id
    550550 
    551551    if ( empty($post_ids) ) 
     
    553553 
    554554    if ( is_array($post_ids) ) 
    555         $post_ids = implode(',', $post_ids); 
    556  
    557     $dogs = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2cat WHERE post_id IN ($post_ids)"); 
     555        $post_id_list = implode(',', $post_ids); 
     556 
     557    $post_id_array = (array) explode(',', $post_ids); 
     558    $count = count( $post_id_array); 
     559    for ( $i = 0; $i < $count; $i++ ) { 
     560        $post_id = $post_id_array[ $i ]; 
     561        if ( isset( $category_cache[$blog_id][$post_id] ) ) { 
     562            unset( $post_id_array[ $i ] ); 
     563            continue; 
     564        } 
     565    } 
     566    if ( count( $post_id_array ) == 0 ) 
     567        return; 
     568    $post_id_list = join( ',', $post_id_array ); // with already cached stuff removed 
     569 
     570    $dogs = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2cat WHERE post_id IN ($post_id_list)"); 
    558571 
    559572    if ( empty($dogs) ) 
     
    561574 
    562575    foreach ($dogs as $catt) 
    563         $category_cache[$catt->post_id][$catt->category_id] = &get_category($catt->category_id); 
     576        $category_cache[$blog_id][$catt->post_id][$catt->category_id] = &get_category($catt->category_id); 
    564577} 
    565578 
     
    591604    $post_id_list = preg_replace('|[^0-9,]|', '', $post_id_list); 
    592605 
     606    if ( empty( $post_id_list ) ) 
     607        return false; 
     608 
    593609    // we're marking each post as having its meta cached (with no keys... empty array), to prevent posts with no meta keys from being queried again 
    594610    // any posts that DO have keys will have this empty array overwritten with a proper array, down below 
    595     $post_id_array = explode(',', $post_id_list); 
    596     foreach ( (array) $post_id_array as $pid ) 
    597         $post_meta_cache[$pid] = array(); 
     611    $post_id_array = (array) explode(',', $post_id_list); 
     612    $count = count( $post_id_array); 
     613    for ( $i = 0; $i < $count; $i++ ) { 
     614        $post_id = $post_id_array[ $i ]; 
     615        if ( isset( $post_meta_cache[$blog_id][$post_id] ) ) { // If the meta is already cached 
     616            unset( $post_id_array[ $i ] ); 
     617            continue; 
     618        } 
     619        $post_meta_cache[$blog_id][$post_id] = array(); 
     620    } 
     621    if ( count( $post_id_array ) == 0 ) 
     622        return; 
     623    $post_id_list = join( ',', $post_id_array ); // with already cached stuff removeds 
    598624 
    599625    // Get post-meta info 
  • trunk/wp-includes/query.php

    r4495 r4517  
    10131013        } 
    10141014 
     1015        $this->posts = apply_filters('the_posts', $this->posts); 
     1016 
    10151017        update_post_caches($this->posts); 
    10161018 
    1017         $this->posts = apply_filters('the_posts', $this->posts); 
    10181019        $this->post_count = count($this->posts); 
    10191020        if ($this->post_count > 0) {