WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/30/2007 03:36:59 AM (14 years ago)
Author:
ryan
Message:

Some term caching. see #4189

File:
1 edited

Legend:

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

    r5592 r5598  
    16571657
    16581658function clean_post_cache($id) {
    1659     global $post_cache, $post_meta_cache, $category_cache, $tag_cache, $blog_id;
     1659    global $post_cache, $post_meta_cache, $post_term_cache, $blog_id;
    16601660
    16611661    if ( isset( $post_cache[$blog_id][$id] ) )
     
    16651665        unset( $post_meta_cache[$blog_id][$id] );
    16661666
    1667     if ( isset( $category_cache[$blog_id][$id]) )
    1668         unset ( $category_cache[$blog_id][$id] );
    1669 
    1670     if ( isset( $tag_cache[$blog_id][$id]) )
    1671         unset ( $tag_cache[$blog_id][$id] );
     1667    if ( isset( $post_term_cache[$blog_id][$id]) )
     1668        unset ( $post_term_cache[$blog_id][$id] );
    16721669}
    16731670
     
    16951692}
    16961693
    1697 function update_post_category_cache($post_ids) {
    1698     global $wpdb, $term_cache, $blog_id;
    1699     // TODO
    1700     return;
     1694function &get_post_term_cache($id, $taxonomy) {
     1695    global $post_term_cache, $blog_id;
     1696
     1697    if ( isset($post_term_cache[$blog_id][$id][$taxonomy]) )
     1698        return $post_term_cache[$blog_id][$id][$taxonomy];
     1699
     1700    return false;
     1701}
     1702
     1703// TODO abstract this to work for any object.
     1704function update_post_term_cache($post_ids) {
     1705    global $wpdb, $post_term_cache, $blog_id;
     1706
    17011707    if ( empty($post_ids) )
    17021708        return;
     
    17091715    for ( $i = 0; $i < $count; $i++ ) {
    17101716        $post_id = (int) $post_id_array[ $i ];
    1711         if ( isset( $term_cache[$blog_id][$post_id] ) ) {
     1717        if ( isset( $post_term_cache[$blog_id][$post_id] ) ) {
    17121718            unset( $post_id_array[ $i ] );
    17131719            continue;
     
    17171723        return;
    17181724
    1719     $dogs = get_object_terms($post_id_array, array('category', 'post_tag'));
    1720 
    1721     if ( empty($dogs) )
     1725    $terms = get_object_terms($post_id_array, array('category', 'post_tag'), 'fields=all_with_object_id');
     1726
     1727    if ( empty($terms) )
    17221728        return;
    17231729
    1724     foreach ($dogs as $catt) {
    1725         $term_cache[$blog_id][$catt->post_id][$catt->taxonomy][$catt->category_id] = &get_category($catt->category_id);
     1730    foreach ( $terms as $term )
     1731        $post_term_cache[$blog_id][$term->object_id][$term->taxonomy][$term->term_id] = $term;
     1732
     1733    foreach ( $post_id_array as $id ) {
     1734        if ( ! isset($post_term_cache[$blog_id][$id]) ) {
     1735            $post_term_cache[$blog_id][$id]['category'] = array();
     1736            $post_term_cache[$blog_id][$id]['post_tag'] = array();
     1737        }
    17261738    }
    17271739}
     
    17431755    $post_id_list = implode(',', $post_id_array);
    17441756
    1745     update_post_category_cache($post_id_list);
     1757    update_post_term_cache($post_id_list);
    17461758
    17471759    update_postmeta_cache($post_id_list);
Note: See TracChangeset for help on using the changeset viewer.