Index: modules/taxonomy/taxonomy.module =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v retrieving revision 1.414.2.5 diff -u -p -r1.414.2.5 taxonomy.module --- modules/taxonomy/taxonomy.module 17 Sep 2008 12:55:37 -0000 1.414.2.5 +++ modules/taxonomy/taxonomy.module 24 Mar 2009 22:51:37 -0000 @@ -900,24 +900,23 @@ function taxonomy_get_synonym_root($syno function taxonomy_term_count_nodes($tid, $type = 0) { static $count; - if (!isset($count[$type])) { - // $type == 0 always evaluates TRUE if $type is a string + $term = taxonomy_get_term($tid); + $tree = taxonomy_get_tree($term->vid, $tid); + + $tids = array($tid); + foreach ($tree as $descendant) { + $tids[] = $descendant->tid; + } + + if (!isset($count[$type][$tid])) { if (is_numeric($type)) { - $result = db_query(db_rewrite_sql('SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 GROUP BY t.tid')); + $count[$type][$tid] = db_result(db_query(db_rewrite_sql("SELECT COUNT(DISTINCT(n.nid)) AS count FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 AND t.tid IN (%s)"), implode(',', $tids))); } else { - $result = db_query(db_rewrite_sql("SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 AND n.type = '%s' GROUP BY t.tid"), $type); + $count[$type][$tid] = db_result(db_query(db_rewrite_sql("SELECT COUNT(DISTINCT(n.nid)) AS count FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 AND n.type = '%s' AND t.tid IN (%s)"), $type, implode(',', $tids))); } - $count[$type] = array(); - while ($term = db_fetch_object($result)) { - $count[$type][$term->tid] = $term->c; - } - } - $children_count = 0; - foreach (_taxonomy_term_children($tid) as $c) { - $children_count += taxonomy_term_count_nodes($c, $type); } - return $children_count + (isset($count[$type][$tid]) ? $count[$type][$tid] : 0); + return $count[$type][$tid]; } /**