Reduce queries.

git-svn-id: http://svn.automattic.com/wordpress/trunk@727 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
saxmatt 2004-01-06 12:44:46 +00:00
parent 572ba33802
commit a8b5faacdc
2 changed files with 32 additions and 8 deletions

View File

@ -167,6 +167,7 @@ if ((empty($cat)) || ($cat == 'all') || ($cat == '0')) {
if ('' != $category_name) {
$category_name = preg_replace('|[^a-z0-9-/]|', '', $category_name);
$tables = ", $tablepost2cat, $tablecategories";
$join = " LEFT JOIN $tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) LEFT JOIN $tablecategories ON ($tablepost2cat.category_id = $tablecategories.cat_ID) ";
$whichcat = " AND (category_nicename = '$category_name') ";
$cat = $wpdb->get_var("SELECT cat_ID FROM $tablecategories WHERE category_nicename = '$category_name'");
@ -319,6 +320,25 @@ if ($preview) {
// echo $request;
$posts = $wpdb->get_results($request);
// Get the categories for all the posts
foreach ($posts as $post) {
$post_id_list[] = $post->ID;
}
$post_id_list = implode(',', $post_id_list);
$dogs = $wpdb->get_results("SELECT DISTINCT
ID, category_id, cat_name, category_nicename, category_description
FROM $tablecategories, $tablepost2cat, $tableposts
WHERE category_id = cat_ID AND post_id = ID AND post_id IN ($post_id_list)");
foreach ($dogs as $catt) {
$category_cache[$catt->ID][] = $catt;
}
// Do the same for comment numbers
if (1 == count($posts)) {
if ($p || $name) {
$more = 1;

View File

@ -1332,14 +1332,18 @@ function posts_nav_link($sep=' :: ', $prelabel='<< Previous Page', $nxtlabel='Ne
/***** Category tags *****/
function get_the_category() {
global $post, $tablecategories, $tablepost2cat, $wpdb;
$categories = $wpdb->get_results("
SELECT category_id, cat_name, category_nicename, category_description
FROM $tablecategories, $tablepost2cat
WHERE $tablepost2cat.category_id = cat_ID AND $tablepost2cat.post_id = $post->ID
");
return $categories;
global $post, $tablecategories, $tablepost2cat, $wpdb, $category_cache;
if ($category_cache[$post->ID]) {
return $category_cache[$post->ID];
} else {
$categories = $wpdb->get_results("
SELECT category_id, cat_name, category_nicename, category_description
FROM $tablecategories, $tablepost2cat
WHERE $tablepost2cat.category_id = cat_ID AND $tablepost2cat.post_id = $post->ID
");
return $categories;
}
}
function get_category_link($echo = false, $category_id, $category_nicename) {