This query shaved a good .1 or .2 second off the query for sites with a lot of nodes/terms.

http://pastie.org/private/zqrfidji7soemczrjhjbqg

Sorry for not having a real patch, I'm contributing on behalf of a coworker.

Comments

greggles’s picture

Of course that's wrong...it needs to be using db_query_range and limiting to 1 result.

dstol’s picture

Status: Active » Needs work

It seems that your version of taxonomy menu is hacked up a little. I'd be interested in seeing more of the hacked version if it's possible.

http://drupalcode.org/project/taxonomy_menu.git/blob/aae80a0197cc6bb14b0...

greggles’s picture

I guess we added caching there prior to updating this query and adding a little more caching.

/**
 * used to get the count without children
 *
 * @param $tid
 */
function _taxonomy_menu_term_count($tid) {
  // Construct a cache ID
  $cid = 'taxonomy_menu:term_count:' . $tid;

  // Try to get the item from the cache
  $cache = cache_get($cid);
  if ($cache) {
    // If we got it from the cache, return that.
    return $cache->data;
  }

  // It is not in the cache, so we issue a query
  $data = db_result(db_query_range('SELECT n.nid AS c FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 AND t.tid = %d', array($tid), 0, 1));
  // We store it in the cache
  cache_set($cid, $data, 'cache', REQUEST_TIME + 1215);
  // We return the result
  return $data;
}
dstol’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

The Drupal 6 version is no longer supported