Make WordPress Core


Ignore:
Timestamp:
05/31/2007 09:38:33 PM (19 years ago)
Author:
ryan
Message:

Abstract object term cache a bit more. see #4189

File:
1 edited

Legend:

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

    r5598 r5616  
    16651665                unset( $post_meta_cache[$blog_id][$id] );
    16661666
    1667         if ( isset( $post_term_cache[$blog_id][$id]) )
    1668                 unset ( $post_term_cache[$blog_id][$id] );
     1667        clean_object_term_cache($id, 'post');
    16691668}
    16701669
     
    16901689        wp_cache_delete( 'all_page_ids', 'pages' );
    16911690        wp_cache_delete( 'get_pages', 'page' );
    1692 }
    1693 
    1694 function &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.
    1704 function update_post_term_cache($post_ids) {
    1705         global $wpdb, $post_term_cache, $blog_id;
    1706 
    1707         if ( empty($post_ids) )
    1708                 return;
    1709 
    1710         if ( is_array($post_ids) )
    1711                 $post_id_list = implode(',', $post_ids);
    1712 
    1713         $post_id_array = (array) explode(',', $post_ids);
    1714         $count = count( $post_id_array);
    1715         for ( $i = 0; $i < $count; $i++ ) {
    1716                 $post_id = (int) $post_id_array[ $i ];
    1717                 if ( isset( $post_term_cache[$blog_id][$post_id] ) ) {
    1718                         unset( $post_id_array[ $i ] );
    1719                         continue;
    1720                 }
    1721         }
    1722         if ( count( $post_id_array ) == 0 )
    1723                 return;
    1724 
    1725         $terms = get_object_terms($post_id_array, array('category', 'post_tag'), 'fields=all_with_object_id');
    1726 
    1727         if ( empty($terms) )
    1728                 return;
    1729 
    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                 }
    1738         }
    17391691}
    17401692
     
    17551707        $post_id_list = implode(',', $post_id_array);
    17561708
    1757         update_post_term_cache($post_id_list);
     1709        update_object_term_cache($post_id_list, 'post');
    17581710
    17591711        update_postmeta_cache($post_id_list);
Note: See TracChangeset for help on using the changeset viewer.