When the query in taxonomy_term_count_nodes returns no rows, $count[$type] is never set. Therefore subsequent calls to this function for that type have to run the query again.

I don't have easy access to cvs and diff, so I'll roll a patch later today. The fix is one line before the while loop:
$count[$type] = array();

CommentFileSizeAuthor
#1 taxonomy_patch.diff770 bytesIsland Usurper

Comments

Island Usurper’s picture

Status: Active » Needs review
StatusFileSize
new770 bytes

The long awaited patch is here at last.

Island Usurper’s picture

Title: taxonomy_term_count_nodes does not cache the empty result » taxonomy_term_count_nodes does not cache the 0 result
Version: 6.x-dev » 5.7
Priority: Minor » Normal

Updating to show that more people have noticed this bug. Duplicate issue found at #259243: Wrong cache of node count for taxonomy when count is 0 in function taxonomy_term_count_nodes()

drumm’s picture

Version: 5.7 » 7.x-dev
Status: Needs review » Reviewed & tested by the community

Committed to 5.x.

Applies to 6.x and HEAD, so needs to be committed there.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD and DRUPAL-6.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.