This makes things a little more interesting and cacheable (sp?)

git-svn-id: http://svn.automattic.com/wordpress/trunk@4517 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
matt 2006-11-23 15:38:22 +00:00
parent 384ec6e6c5
commit 624c94b57e
2 changed files with 35 additions and 8 deletions

View File

@ -546,21 +546,34 @@ function clean_page_cache($id) {
}
function update_post_category_cache($post_ids) {
global $wpdb, $category_cache;
global $wpdb, $category_cache, $blog_id;
if ( empty($post_ids) )
return;
if ( is_array($post_ids) )
$post_ids = implode(',', $post_ids);
$post_id_list = implode(',', $post_ids);
$dogs = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2cat WHERE post_id IN ($post_ids)");
$post_id_array = (array) explode(',', $post_ids);
$count = count( $post_id_array);
for ( $i = 0; $i < $count; $i++ ) {
$post_id = $post_id_array[ $i ];
if ( isset( $category_cache[$blog_id][$post_id] ) ) {
unset( $post_id_array[ $i ] );
continue;
}
}
if ( count( $post_id_array ) == 0 )
return;
$post_id_list = join( ',', $post_id_array ); // with already cached stuff removed
$dogs = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2cat WHERE post_id IN ($post_id_list)");
if ( empty($dogs) )
return;
foreach ($dogs as $catt)
$category_cache[$catt->post_id][$catt->category_id] = &get_category($catt->category_id);
$category_cache[$blog_id][$catt->post_id][$catt->category_id] = &get_category($catt->category_id);
}
function update_post_caches(&$posts) {
@ -590,11 +603,24 @@ function update_postmeta_cache($post_id_list = '') {
// We should validate this comma-separated list for the upcoming SQL query
$post_id_list = preg_replace('|[^0-9,]|', '', $post_id_list);
if ( empty( $post_id_list ) )
return false;
// 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
// any posts that DO have keys will have this empty array overwritten with a proper array, down below
$post_id_array = explode(',', $post_id_list);
foreach ( (array) $post_id_array as $pid )
$post_meta_cache[$pid] = array();
$post_id_array = (array) explode(',', $post_id_list);
$count = count( $post_id_array);
for ( $i = 0; $i < $count; $i++ ) {
$post_id = $post_id_array[ $i ];
if ( isset( $post_meta_cache[$blog_id][$post_id] ) ) { // If the meta is already cached
unset( $post_id_array[ $i ] );
continue;
}
$post_meta_cache[$blog_id][$post_id] = array();
}
if ( count( $post_id_array ) == 0 )
return;
$post_id_list = join( ',', $post_id_array ); // with already cached stuff removeds
// Get post-meta info
if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id IN($post_id_list) ORDER BY post_id, meta_key", ARRAY_A) ) {

View File

@ -1012,9 +1012,10 @@ class WP_Query {
}
}
$this->posts = apply_filters('the_posts', $this->posts);
update_post_caches($this->posts);
$this->posts = apply_filters('the_posts', $this->posts);
$this->post_count = count($this->posts);
if ($this->post_count > 0) {
$this->post = $this->posts[0];