Make WordPress Core


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

Some optimizations in queries and code.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.