Make WordPress Core

Changeset 727


Ignore:
Timestamp:
01/06/2004 12:44:46 PM (22 years ago)
Author:
saxmatt
Message:

Reduce queries.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-blog-header.php

    r726 r727  
    168168if ('' != $category_name) {
    169169    $category_name = preg_replace('|[^a-z0-9-/]|', '', $category_name);
     170    $tables = ", $tablepost2cat, $tablecategories";
    170171    $join = " LEFT JOIN $tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) LEFT JOIN $tablecategories ON ($tablepost2cat.category_id = $tablecategories.cat_ID) ";
    171172    $whichcat = " AND (category_nicename = '$category_name') ";
     
    320321$posts = $wpdb->get_results($request);
    321322
     323
     324// Get the categories for all the posts
     325foreach ($posts as $post) {
     326    $post_id_list[] = $post->ID;
     327}
     328$post_id_list = implode(',', $post_id_list);
     329
     330$dogs = $wpdb->get_results("SELECT DISTINCT
     331    ID, category_id, cat_name, category_nicename, category_description
     332    FROM $tablecategories, $tablepost2cat, $tableposts
     333    WHERE category_id = cat_ID AND post_id = ID AND post_id IN ($post_id_list)");
     334   
     335foreach ($dogs as $catt) {
     336    $category_cache[$catt->ID][] = $catt;
     337}
     338
     339// Do the same for comment numbers
     340
     341
    322342if (1 == count($posts)) {
    323343    if ($p || $name) {
  • trunk/wp-includes/template-functions.php

    r725 r727  
    13331333
    13341334function get_the_category() {
    1335     global $post, $tablecategories, $tablepost2cat, $wpdb;
    1336     $categories = $wpdb->get_results("
    1337         SELECT category_id, cat_name, category_nicename, category_description
    1338         FROM  $tablecategories, $tablepost2cat
    1339         WHERE $tablepost2cat.category_id = cat_ID AND $tablepost2cat.post_id = $post->ID
    1340         ");
    1341 
    1342     return $categories;
     1335    global $post, $tablecategories, $tablepost2cat, $wpdb, $category_cache;
     1336    if ($category_cache[$post->ID]) {
     1337        return $category_cache[$post->ID];
     1338    } else {
     1339        $categories = $wpdb->get_results("
     1340            SELECT category_id, cat_name, category_nicename, category_description
     1341            FROM  $tablecategories, $tablepost2cat
     1342            WHERE $tablepost2cat.category_id = cat_ID AND $tablepost2cat.post_id = $post->ID
     1343            ");
     1344   
     1345        return $categories;
     1346    }
    13431347}
    13441348
Note: See TracChangeset for help on using the changeset viewer.