Changeset 5616
- Timestamp:
- 05/31/2007 09:38:33 PM (18 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/category-template.php
r5598 r5616 67 67 $id = (int) $post->ID; 68 68 69 $categories = get_ post_term_cache($id, 'category');69 $categories = get_object_term_cache($id, 'category'); 70 70 if ( false === $categories ) 71 71 $categories = get_object_terms($id, 'category'); … … 419 419 $id = (int) $post->ID; 420 420 421 $tags = get_ post_term_cache($id, 'post_tag');421 $tags = get_object_term_cache($id, 'post_tag'); 422 422 if ( false === $tags ) 423 423 $tags = get_object_terms($id, 'post_tag'); -
trunk/wp-includes/post.php
r5598 r5616 1665 1665 unset( $post_meta_cache[$blog_id][$id] ); 1666 1666 1667 if ( isset( $post_term_cache[$blog_id][$id]) ) 1668 unset ( $post_term_cache[$blog_id][$id] ); 1667 clean_object_term_cache($id, 'post'); 1669 1668 } 1670 1669 … … 1690 1689 wp_cache_delete( 'all_page_ids', 'pages' ); 1691 1690 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 }1739 1691 } 1740 1692 … … 1755 1707 $post_id_list = implode(',', $post_id_array); 1756 1708 1757 update_ post_term_cache($post_id_list);1709 update_object_term_cache($post_id_list, 'post'); 1758 1710 1759 1711 update_postmeta_cache($post_id_list); -
trunk/wp-includes/taxonomy.php
r5613 r5616 400 400 } 401 401 402 function get_object_taxonomies($object_type) { 403 global $wp_taxonomies; 404 405 $taxonomies = array(); 406 foreach ( $wp_taxonomies as $taxonomy ) { 407 if ( $object_type == $taxonomy->object_type ) 408 $taxonomies[] = $taxonomy->name; 409 } 410 411 return $taxonomies; 412 } 413 402 414 /** 403 415 * Returns the terms associated with the given object(s), in the supplied taxonomies. … … 408 420 function get_object_terms($object_ids, $taxonomies, $args = array()) { 409 421 global $wpdb; 410 error_log("Objects: " . var_export($object_ids, true), 0); 422 411 423 if ( !is_array($taxonomies) ) 412 424 $taxonomies = array($taxonomies); … … 716 728 } 717 729 730 function clean_object_term_cache($object_ids, $object_type) { 731 global $object_term_cache, $blog_id; 732 733 if ( !is_array($ids) ) 734 $ids = array($ids); 735 736 $taxonomies = get_object_taxonomies($object_type); 737 738 foreach ( $ids as $id ) { 739 foreach ( $taxonomies as $taxonomy ) { 740 if ( isset($object_term_cache[$blog_id][$id][$taxonomy]) ) 741 unset($object_term_cache[$blog_id][$id][$taxonomy]); 742 } 743 } 744 } 745 746 function &get_object_term_cache($id, $taxonomy) { 747 global $object_term_cache, $blog_id; 748 749 if ( isset($object_term_cache[$blog_id][$id][$taxonomy]) ) 750 return $object_term_cache[$blog_id][$id][$taxonomy]; 751 752 if ( isset($object_term_cache[$blog_id][$id]) ) 753 return array(); 754 755 return false; 756 } 757 758 function update_object_term_cache($object_ids, $object_type) { 759 global $wpdb, $object_term_cache, $blog_id; 760 761 if ( empty($object_ids) ) 762 return; 763 764 if ( !is_array($object_ids) ) 765 $object_ids = explode(',', $object_ids); 766 767 $count = count( $object_ids); 768 for ( $i = 0; $i < $count; $i++ ) { 769 $object_id = (int) $object_ids[ $i ]; 770 if ( isset( $object_term_cache[$blog_id][$object_id] ) ) { 771 unset( $object_ids[ $i ] ); 772 continue; 773 } 774 } 775 776 if ( count( $object_ids ) == 0 ) 777 return; 778 779 $terms = get_object_terms($object_ids, get_object_taxonomies($object_type), 'fields=all_with_object_id'); 780 781 if ( empty($terms) ) 782 return; 783 784 foreach ( $terms as $term ) 785 $object_term_cache[$blog_id][$term->object_id][$term->taxonomy][$term->term_id] = $term; 786 787 foreach ( $object_ids as $id ) { 788 if ( ! isset($object_term_cache[$blog_id][$id]) ) 789 $object_term_cache[$blog_id][$id] = array(); 790 } 791 } 792 718 793 function _get_term_hierarchy($taxonomy) { 719 794 // TODO Make sure taxonomy is hierarchical
Note: See TracChangeset
for help on using the changeset viewer.