mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 09:37:42 +01:00
Some optimizations in queries and code.
git-svn-id: http://svn.automattic.com/wordpress/trunk@2976 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e0e5a1659c
commit
2718217d3b
@ -1275,24 +1275,29 @@ function update_post_caches(&$posts) {
|
|||||||
|
|
||||||
// Get the categories for all the posts
|
// Get the categories for all the posts
|
||||||
for ($i = 0; $i < count($posts); $i++) {
|
for ($i = 0; $i < count($posts); $i++) {
|
||||||
$post_id_list[] = $posts[$i]->ID;
|
$post_id_array[] = $posts[$i]->ID;
|
||||||
$post_cache[$posts[$i]->ID] = &$posts[$i];
|
$post_cache[$posts[$i]->ID] = &$posts[$i];
|
||||||
}
|
}
|
||||||
|
|
||||||
$post_id_list = implode(',', $post_id_list);
|
$post_id_list = implode(',', $post_id_array);
|
||||||
|
|
||||||
update_post_category_cache($post_id_list);
|
update_post_category_cache($post_id_list);
|
||||||
|
|
||||||
// Do the same for comment numbers
|
// Do the same for comment numbers
|
||||||
$comment_counts = $wpdb->get_results("SELECT ID, COUNT( comment_ID ) AS ccount
|
$comment_counts = $wpdb->get_results("SELECT comment_post_ID, COUNT( comment_ID ) AS ccount
|
||||||
FROM $wpdb->posts
|
FROM $wpdb->comments
|
||||||
LEFT JOIN $wpdb->comments ON ( comment_post_ID = ID AND comment_approved = '1')
|
WHERE comment_post_ID IN ($post_id_list)
|
||||||
WHERE ID IN ($post_id_list)
|
AND comment_approved = '1'
|
||||||
GROUP BY ID");
|
GROUP BY comment_post_ID");
|
||||||
|
|
||||||
if ( $comment_counts ) {
|
if ( $comment_counts ) {
|
||||||
foreach ($comment_counts as $comment_count)
|
foreach ($comment_counts as $comment_count) {
|
||||||
$comment_count_cache["$comment_count->ID"] = $comment_count->ccount;
|
$comment_count_cache["$comment_count->comment_post_ID"] = $comment_count->ccount;
|
||||||
|
$got_count[] = $comment_count->comment_post_ID;
|
||||||
|
}
|
||||||
|
foreach ( $post_id_array as $id )
|
||||||
|
if ( !in_array( $id, $got_count ) )
|
||||||
|
$comment_count_cache["$id"] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get post-meta info
|
// Get post-meta info
|
||||||
|
@ -92,14 +92,34 @@ if ( !function_exists('get_userdatabylogin') ) :
|
|||||||
function get_userdatabylogin($user_login) {
|
function get_userdatabylogin($user_login) {
|
||||||
global $cache_userdata, $wpdb;
|
global $cache_userdata, $wpdb;
|
||||||
$user_login = sanitize_user( $user_login );
|
$user_login = sanitize_user( $user_login );
|
||||||
|
|
||||||
if ( empty( $user_login ) )
|
if ( empty( $user_login ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( isset( $cache_userdata[$user_login] ) )
|
if ( isset( $cache_userdata[$user_login] ) )
|
||||||
return $cache_userdata[$user_login];
|
return $cache_userdata[$user_login];
|
||||||
|
|
||||||
$user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$user_login'");
|
|
||||||
|
|
||||||
return get_userdata( $user_id );
|
if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'") )
|
||||||
|
return $cache_userdata[$user_login] = false;
|
||||||
|
|
||||||
|
$metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user->ID'");
|
||||||
|
|
||||||
|
foreach ( $metavalues as $meta ) {
|
||||||
|
@ $value = unserialize($meta->meta_value);
|
||||||
|
if ($value === FALSE)
|
||||||
|
$value = $meta->meta_value;
|
||||||
|
$user->{$meta->meta_key} = $value;
|
||||||
|
|
||||||
|
// We need to set user_level from meta, not row
|
||||||
|
if ( $wpdb->prefix . 'user_level' == $meta->meta_key )
|
||||||
|
$user->user_level = $meta->meta_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cache_userdata[$user->ID] = $user;
|
||||||
|
$cache_userdata[$cache_userdata[$user->ID]->user_login] =& $cache_userdata[$user->ID];
|
||||||
|
|
||||||
|
return $cache_userdata[$user->ID];
|
||||||
|
|
||||||
}
|
}
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ function get_category_link($category_id) {
|
|||||||
$catlink = $wp_rewrite->get_category_permastruct();
|
$catlink = $wp_rewrite->get_category_permastruct();
|
||||||
|
|
||||||
if ( empty($catlink) ) {
|
if ( empty($catlink) ) {
|
||||||
$file = get_settings('home') . '/' . get_settings('blogfilename');
|
$file = get_settings('home') . '/';
|
||||||
$catlink = $file . '?cat=' . $category_id;
|
$catlink = $file . '?cat=' . $category_id;
|
||||||
} else {
|
} else {
|
||||||
$category = &get_category($category_id);
|
$category = &get_category($category_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user