Changeset 4517
- Timestamp:
- 11/23/06 15:38:22 (2 years ago)
- Files:
-
- trunk/wp-includes/functions.php (modified) (4 diffs)
- trunk/wp-includes/query.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/wp-includes/functions.php
r4513 r4517 547 547 548 548 function update_post_category_cache($post_ids) { 549 global $wpdb, $category_cache ;549 global $wpdb, $category_cache, $blog_id; 550 550 551 551 if ( empty($post_ids) ) … … 553 553 554 554 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)"); 558 571 559 572 if ( empty($dogs) ) … … 561 574 562 575 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); 564 577 } 565 578 … … 591 604 $post_id_list = preg_replace('|[^0-9,]|', '', $post_id_list); 592 605 606 if ( empty( $post_id_list ) ) 607 return false; 608 593 609 // 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 594 610 // 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 598 624 599 625 // Get post-meta info trunk/wp-includes/query.php
r4495 r4517 1013 1013 } 1014 1014 1015 $this->posts = apply_filters('the_posts', $this->posts); 1016 1015 1017 update_post_caches($this->posts); 1016 1018 1017 $this->posts = apply_filters('the_posts', $this->posts);1018 1019 $this->post_count = count($this->posts); 1019 1020 if ($this->post_count > 0) {
