Changeset 5598
- Timestamp:
- 05/30/2007 03:36:59 AM (16 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/category-template.php
r5590 r5598 61 61 62 62 function get_the_category($id = false) { 63 global $post, $ category_cache, $blog_id;63 global $post, $term_cache, $blog_id; 64 64 65 65 $id = (int) $id; … … 67 67 $id = (int) $post->ID; 68 68 69 $categories = get_object_terms($id, 'category'); 69 $categories = get_post_term_cache($id, 'category'); 70 if ( false === $categories ) 71 $categories = get_object_terms($id, 'category'); 70 72 71 73 if ( !empty($categories) ) … … 417 419 $id = (int) $post->ID; 418 420 419 $tags = wp_get_post_tags( $id ); 421 $tags = get_post_term_cache($id, 'post_tag'); 422 if ( false === $tags ) 423 $tags = get_object_terms($id, 'post_tag'); 424 420 425 $tags = apply_filters( 'get_the_tags', $tags ); 421 426 if ( empty( $tags ) ) -
trunk/wp-includes/post.php
r5592 r5598 1657 1657 1658 1658 function 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; 1660 1660 1661 1661 if ( isset( $post_cache[$blog_id][$id] ) ) … … 1665 1665 unset( $post_meta_cache[$blog_id][$id] ); 1666 1666 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] ); 1672 1669 } 1673 1670 … … 1695 1692 } 1696 1693 1697 function update_post_category_cache($post_ids) { 1698 global $wpdb, $term_cache, $blog_id; 1699 // TODO 1700 return; 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 1701 1707 if ( empty($post_ids) ) 1702 1708 return; … … 1709 1715 for ( $i = 0; $i < $count; $i++ ) { 1710 1716 $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] ) ) { 1712 1718 unset( $post_id_array[ $i ] ); 1713 1719 continue; … … 1717 1723 return; 1718 1724 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) ) 1722 1728 return; 1723 1729 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 } 1726 1738 } 1727 1739 } … … 1743 1755 $post_id_list = implode(',', $post_id_array); 1744 1756 1745 update_post_ category_cache($post_id_list);1757 update_post_term_cache($post_id_list); 1746 1758 1747 1759 update_postmeta_cache($post_id_list); -
trunk/wp-includes/taxonomy.php
r5597 r5598 429 429 430 430 if ( 'all' == $fields ) 431 $select_this = 't.* ';431 $select_this = 't.*, tt.*'; 432 432 else if ( 'ids' == $fields ) 433 433 $select_this = 't.term_id'; 434 else if ( 'all_with_object_id' == $fields ) 435 $select_this = 't.*, tt.*, tr.object_id'; 434 436 435 437 $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) ORDER BY $orderby $order"; 436 438 437 if ( 'all' == $fields ) 438 $taxonomy_data = $wpdb->get_results($query); 439 else if ( 'ids' == $fields ) 440 $taxonomy_data = $wpdb->get_col($query); 441 else if ( 'tt_ids' == $fields ) 442 $taxonomy_data = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) ORDER BY tr.term_taxonomy_id $order"); 443 444 if ( ! $taxonomy_data ) 439 if ( 'all' == $fields || 'all_with_object_id' == $fields ) { 440 $terms = $wpdb->get_results($query); 441 update_term_cache($terms); 442 } else if ( 'ids' == $fields ) { 443 $terms = $wpdb->get_col($query); 444 } else if ( 'tt_ids' == $fields ) { 445 $terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) ORDER BY tr.term_taxonomy_id $order"); 446 } 447 448 if ( ! $terms ) 445 449 return array(); 446 450 447 return $t axonomy_data;451 return $terms; 448 452 } 449 453 … … 554 558 $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where ORDER BY $orderby $order $number"; 555 559 556 if ( 'all' == $fields ) 560 if ( 'all' == $fields ) { 557 561 $terms = $wpdb->get_results($query); 558 else if ( 'ids' == $fields ) 562 update_term_cache($terms); 563 } else if ( 'ids' == $fields ) { 559 564 $terms = $wpdb->get_col($query); 565 } 560 566 561 567 if ( empty($terms) ) … … 591 597 592 598 $cache[ $key ] = $terms; 593 wp_cache_ add( 'get_terms', $cache, 'term' );599 wp_cache_set( 'get_terms', $cache, 'term' ); 594 600 595 601 $terms = apply_filters('get_terms', $terms, $taxonomies, $args); … … 680 686 } 681 687 688 function update_term_cache($terms, $taxonomy = '') { 689 foreach ( $terms as $term ) { 690 $term_taxonomy = $taxonomy; 691 if ( empty($term_taxonomy) ) 692 $term_taxonomy = $term->taxonomy; 693 694 wp_cache_add($term->term_id, $term, $term_taxonomy); 695 } 696 } 697 682 698 function clean_term_cache($ids, $taxonomy) { 683 699 if ( !is_array($ids) )
Note: See TracChangeset
for help on using the changeset viewer.