Index: tagadelic.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tagadelic/tagadelic.module,v
retrieving revision 1.40.2.3
diff -u -p -r1.40.2.3 tagadelic.module
--- tagadelic.module	13 Nov 2008 11:36:32 -0000	1.40.2.3
+++ tagadelic.module	23 Dec 2008 12:05:07 -0000
@@ -2,6 +2,11 @@
 // $Id: tagadelic.module,v 1.40.2.3 2008/11/13 11:36:32 ber Exp $
 
 /**
+ * @file
+ * Tag clouds for drupal
+ */
+
+/**
  * Implementation of hook_help
  */
 function tagadelic_help($path, $arg) {
@@ -349,7 +354,7 @@ function tagadelic_block($op = 'list', $
       $tags = tagadelic_get_weighted_tags(array($voc->vid), variable_get('tagadelic_levels', 6), variable_get('tagadelic_block_tags_'. $delta, 12));
       $tags = tagadelic_sort_tags($tags);
       $blocks['content'] = theme('tagadelic_weighted', $tags);//return a chunk of 12 tags
-      if (count($tags) >= variable_get('tagadelic_block_tags_'. $delta, 12)) {
+      if (tagadelic_get_tag_count(array($voc->vid)) > variable_get('tagadelic_block_tags_'. $delta, 12)) {
         $blocks['content'] .= theme('tagadelic_more', $voc->vid);//add more link
       }
 
@@ -397,3 +402,40 @@ function tagadelic_theme() {
     'tagadelic_weighted' => array('arguments' => array('terms' => NULL))
   );
 }
+
+/**
+ * Function to retrieve the (possibly cached) total number of terms in a vocabulary/set of vocabularies.
+ * @param $vids. Vocabulary IDs representing the vocabularies where you want the tags from.
+ * @return The number of distinct terms
+ */
+function tagadelic_get_tag_count($vids) {
+  $tagcount = 0;
+
+  // build the options so we can cache multiple versions
+  $options = implode($vids) .'_'. $steps .'_'. $size;
+  
+  // Check if the cache exists
+  $cache_name = 'tagadelic_cache_count_'. $options;
+  $cache = cache_get($cache_name);
+  
+  // make sure cache has data
+  if (isset($cache->data)) {
+    $tagcount = $cache->data;
+  }
+  else {
+    if (!is_array($vids) || count($vids) == 0) {
+      return 0;
+    }
+
+    $result = db_query('SELECT COUNT(*) AS count FROM {term_data} d INNER JOIN {term_node} n ON d.tid = n.tid WHERE d.vid IN ('. substr(str_repeat('%d,', count($vids)), 0, -1) .')', $vids);
+    
+    $count = db_fetch_object($result);
+
+    $tagcount = $count->count;
+
+    cache_set($cache_name, $tagcount, 'cache', CACHE_TEMPORARY);
+  }
+  
+  return $tagcount;
+}
+
