Make WordPress Core

Changeset 2976


Ignore:
Timestamp:
10/29/2005 11:23:17 PM (21 years ago)
Author:
matt
Message:

Some optimizations in queries and code.

Location:
trunk/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r2968 r2976  
    12761276        // Get the categories for all the posts
    12771277        for ($i = 0; $i < count($posts); $i++) {
    1278                 $post_id_list[] = $posts[$i]->ID;
     1278                $post_id_array[] = $posts[$i]->ID;
    12791279                $post_cache[$posts[$i]->ID] = &$posts[$i];
    12801280        }
    12811281
    1282         $post_id_list = implode(',', $post_id_list);
     1282        $post_id_list = implode(',', $post_id_array);
    12831283
    12841284        update_post_category_cache($post_id_list);
    12851285
    12861286        // Do the same for comment numbers
    1287         $comment_counts = $wpdb->get_results("SELECT ID, COUNT( comment_ID ) AS ccount
    1288         FROM $wpdb->posts
    1289         LEFT JOIN $wpdb->comments ON ( comment_post_ID = ID AND comment_approved = '1')
    1290         WHERE ID IN ($post_id_list)
    1291         GROUP BY ID");
     1287        $comment_counts = $wpdb->get_results("SELECT comment_post_ID, COUNT( comment_ID ) AS ccount
     1288        FROM $wpdb->comments
     1289        WHERE comment_post_ID IN ($post_id_list)
     1290        AND comment_approved = '1'
     1291        GROUP BY comment_post_ID");
    12921292
    12931293        if ( $comment_counts ) {
    1294                 foreach ($comment_counts as $comment_count)
    1295                         $comment_count_cache["$comment_count->ID"] = $comment_count->ccount;
     1294                foreach ($comment_counts as $comment_count) {
     1295                        $comment_count_cache["$comment_count->comment_post_ID"] = $comment_count->ccount;
     1296                        $got_count[] = $comment_count->comment_post_ID;
     1297                }
     1298                foreach ( $post_id_array as $id )
     1299                        if ( !in_array( $id, $got_count ) )
     1300                                $comment_count_cache["$id"] = 0;
    12961301        }
    12971302
  • trunk/wp-includes/pluggable-functions.php

    r2872 r2976  
    9393        global $cache_userdata, $wpdb;
    9494        $user_login = sanitize_user( $user_login );
     95
    9596        if ( empty( $user_login ) )
    9697                return false;
     98
    9799        if ( isset( $cache_userdata[$user_login] ) )
    98100                return $cache_userdata[$user_login];
    99        
    100         $user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$user_login'");
    101 
    102         return get_userdata( $user_id );
     101
     102        if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'") )
     103                return $cache_userdata[$user_login] = false;
     104
     105        $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user->ID'");
     106
     107        foreach ( $metavalues as $meta ) {
     108                @ $value = unserialize($meta->meta_value);
     109                if ($value === FALSE)
     110                        $value = $meta->meta_value;
     111                $user->{$meta->meta_key} = $value;
     112
     113                // We need to set user_level from meta, not row
     114                if ( $wpdb->prefix . 'user_level' == $meta->meta_key )
     115                        $user->user_level = $meta->meta_value;
     116        }
     117
     118        $cache_userdata[$user->ID] = $user;
     119        $cache_userdata[$cache_userdata[$user->ID]->user_login] =& $cache_userdata[$user->ID];
     120
     121        return $cache_userdata[$user->ID];
     122
    103123}
    104124endif;
  • trunk/wp-includes/template-functions-category.php

    r2975 r2976  
    2525
    2626        if ( empty($catlink) ) {
    27                 $file = get_settings('home') . '/' . get_settings('blogfilename');
     27                $file = get_settings('home') . '/';
    2828                $catlink = $file . '?cat=' . $category_id;
    2929        } else {
Note: See TracChangeset for help on using the changeset viewer.