Category query speedup and indentation fixes. Hat tip: Scott. http://mosquito.wordpress.org/view.php?id=1005

git-svn-id: https://develop.svn.wordpress.org/trunk@2396 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Matt Mullenweg 2005-03-01 09:10:12 +00:00
parent 0de297805a
commit a0eba624c5
2 changed files with 73 additions and 80 deletions

View File

@ -990,7 +990,6 @@ function get_posts($args) {
function query_posts($query) {
global $wp_query;
return $wp_query->query($query);
}
@ -999,9 +998,8 @@ function update_post_caches($posts) {
global $wpdb;
// No point in doing all this work if we didn't match any posts.
if (! $posts) {
if ( !$posts )
return;
}
// Get the categories for all the posts
foreach ($posts as $post)
@ -1009,13 +1007,13 @@ function update_post_caches($posts) {
$post_id_list = implode(',', $post_id_list);
$dogs = $wpdb->get_results("SELECT DISTINCT
ID, category_id, cat_name, category_nicename, category_description, category_parent
FROM $wpdb->categories, $wpdb->post2cat, $wpdb->posts
WHERE category_id = cat_ID AND post_id = ID AND post_id IN ($post_id_list)");
post_id, category_id, cat_name, category_nicename, category_description, category_parent
FROM $wpdb->categories, $wpdb->post2cat
WHERE category_id = cat_ID AND post_id IN ($post_id_list)");
if ( !empty($dogs) ) {
foreach ($dogs as $catt) {
$category_cache[$catt->ID][$catt->category_id] = $catt;
$category_cache[$catt->post_id][$catt->category_id] = $catt;
}
}
@ -1027,14 +1025,12 @@ function update_post_caches($posts) {
GROUP BY ID");
if ($comment_counts) {
foreach ($comment_counts as $comment_count) {
foreach ($comment_counts as $comment_count)
$comment_count_cache["$comment_count->ID"] = $comment_count->ccount;
}
}
// 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) ) {
// Change from flat structure to hierarchical:
$post_meta_cache = array();
foreach ($meta_list as $metarow) {
@ -1057,10 +1053,9 @@ function update_post_caches($posts) {
function update_category_cache() {
global $cache_categories, $wpdb;
$dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories");
foreach ($dogs as $catt) {
foreach ($dogs as $catt)
$cache_categories[$catt->cat_ID] = $catt;
}
}
function update_user_cache() {
global $cache_userdata, $wpdb;

View File

@ -3,9 +3,8 @@
function get_the_category($id = false) {
global $post, $wpdb, $category_cache;
if (! $id) {
if ( !$id )
$id = $post->ID;
}
if ( $category_cache[$id] ) {
$categories = $category_cache[$id];
@ -15,7 +14,6 @@ function get_the_category($id = false) {
FROM $wpdb->categories, $wpdb->post2cat
WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$id'
");
}
if (!empty($categories))