Category query speedup and indentation fixes. Hat tip: Scott. http://mosquito.wordpress.org/view.php?id=1005
git-svn-id: http://svn.automattic.com/wordpress/trunk@2396 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
442e09db17
commit
2233bfb700
|
@ -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)) {
|
||||
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,9 +1053,8 @@ 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() {
|
||||
|
@ -1071,7 +1066,7 @@ function update_user_cache() {
|
|||
$cache_userdata[$user->user_login] =& $cache_userdata[$user->ID];
|
||||
endforeach;
|
||||
return true;
|
||||
else:
|
||||
else :
|
||||
return false;
|
||||
endif;
|
||||
}
|
||||
|
|
|
@ -3,11 +3,10 @@
|
|||
function get_the_category($id = false) {
|
||||
global $post, $wpdb, $category_cache;
|
||||
|
||||
if (! $id) {
|
||||
if ( !$id )
|
||||
$id = $post->ID;
|
||||
}
|
||||
|
||||
if ($category_cache[$id]) {
|
||||
if ( $category_cache[$id] ) {
|
||||
$categories = $category_cache[$id];
|
||||
} else {
|
||||
$categories = $wpdb->get_results("
|
||||
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue