diff -u'rNF^function' tagadelic/tagadelic.module tagadelic_new/tagadelic.module
--- tagadelic/tagadelic.module	2006-06-13 21:01:53.000000000 -0400
+++ tagadelic_new/tagadelic.module	2006-08-11 17:47:06.000000000 -0400
@@ -51,13 +51,120 @@ function tagadelic_menu($may_cache) {
 
 /**
  * Implementation of hook_nodeapi
- * Yuo will have a nice variable in $node available for processing tags!
+ * You will have a nice variable in $node available for processing tags!
  */
 function tagadelic_nodeapi($node, $op) {
-  if ($op == 'load') {
+/*  if ($op == 'load') {
     $output['tags'] = tagadelic_node_get_terms($node);
     return $output;
   }
+*/
+
+  switch ($op) {
+    case 'load':
+      $output['tags'] = tagadelic_node_get_terms($node);
+      return $output;
+      break;
+    case 'insert':
+    case 'update':
+      tagadelic_index_node('save', $node);
+      break;
+    case 'delete':
+      tagadelic_index_node('delete', $node);
+      break;
+  }
+}
+
+/**
+ * Implementation of hook_taxonomy
+ **/
+ 
+function tagadelic_taxonomy($op, $type, $object = NULL) {
+  switch ($op) {
+    case 'delete':
+      tagadelic_delete_term($type, $object);
+      break;
+    case 'update':
+      if ($type == 'term') {
+        $sql = "UPDATE {tagadelic} SET name = '%s' WHERE tid = %d";
+        db_query($sql, $object['name'], $object['tid']);
+      }
+      break;
+  }
+}
+
+/**
+ * Store tagedalic variables in a table rather than on-the-fly
+ **/
+ 
+function tagadelic_index_node($op, $node) {
+  $tags = array();
+  if(!empty($node->taxonomy)) {
+    foreach ($node->taxonomy as $key => $value) {
+      if (is_numeric($key) && is_array($value)) {
+        foreach ($value as $k => $v) {
+          $tags[] = taxonomy_get_term($v);
+        }
+      }
+    }
+  }
+  
+  if (!empty($node->taxonomy['tags'])) {
+    foreach ($node->taxonomy['tags'] as $vid => $tax) {
+      $words = explode(',', $tax);
+      foreach ($words as $term) {
+        $data = taxonomy_get_term_by_name($term);
+        if(!empty($data)) {
+          foreach ($data as $item) {
+            if ($item->vid == $vid) {
+              $tags[] = $item;
+            }
+          }  
+        }  
+      }  
+    }
+  }
+  switch ($op) {
+    case 'save':
+    case 'delete':
+      $tagwords = array();
+      if (!empty($tags)) {
+        foreach ($tags as $term) {
+          if ($term->tid > 0) {
+	          $check = db_fetch_object(db_query("SELECT node_count FROM {tagadelic} WHERE tid = %d", $term->tid));
+	          $sql = "SELECT COUNT(nid) as count FROM {term_node} WHERE tid = %d";
+	          $count = db_queryd($sql, $term->tid);
+	          $term->node_count = db_fetch_object($count)->count;
+	          if (empty($check)) {
+	            $query = "INSERT into {tagadelic} (tid, name, vid, node_count) VALUES (%d, '%s', %d, %d)";
+	            db_queryd($query, $term->tid, $term->name, $term->vid, $term->node_count);
+	          }
+	          else {
+	            $query = "UPDATE {tagadelic} SET node_count = %d WHERE tid = %d";
+	            db_queryd($query, $term->node_count, $term->tid);
+	          }
+	        }  
+        }
+      }
+      break;
+  }
+}
+
+/**
+ * Store tagedelic variables in a table rather than on-the-fly
+ **/
+
+function tagadelic_delete_term($type, $object) {
+  switch ($type) {
+    case 'term':
+      $sql = "DELETE from {tagadelic} WHERE tid = %d";
+      db_query($sql, $object['tid']);
+      break;
+    case 'vocabulary':
+      $sql = "DELETE from {tagadelic} WHERE vid = %d";
+      db_query($sql, $object['vid']);    
+      break;
+  }
 }
 
 /**
@@ -177,19 +284,21 @@ function tagadelic_tags_lists($node) {
  * API that returns an array with weighted tags
  * This is the hard part. People with better ideas are very very welcome to send these to ber@webschuur.com. Distribution is one thing that needs attention.
  */
-function tagadelic_get_weighted_tags($vids, $steps = 6, $size = 60) {
+function tagadelic_get_weighted_tags($vids, $steps = 10, $size = 1000) {
   if (!is_array($vids) || count($vids) == 0) {
     return array();
   }
 
   // Fetch tags
-  $result = db_query_range('SELECT COUNT(*) AS count, d.tid, d.name, d.vid 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) .') GROUP BY d.tid, d.name ORDER BY count DESC', $vids, 0, $size);
+  //  $result = db_query_range('SELECT COUNT(*) AS count, d.tid, d.name, d.vid 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) .') GROUP BY d.tid, d.name ORDER BY count DESC', $vids, 0, $size);
+  $result = db_query_range("SELECT tid, name, vid, node_count FROM {tagadelic} WHERE vid IN (". substr(str_repeat('%d,', count($vids)), 0, -1) .")", $vids, 0, $size);
 
   // Find minimum and maximum log-count.
   $tags = array();
   $min = 1e9;
   $max = -1e9;
   while ($tag = db_fetch_object($result)) {
+    $tag->count = $tag->node_count;
     $tag->number_of_posts = $tag->count;
     $tag->count = log($tag->count);
     $min = min($min, $tag->count);
diff -u'rNF^function' tagadelic/tagadelic.mysql tagadelic_new/tagadelic.mysql
--- tagadelic/tagadelic.mysql	1969-12-31 19:00:00.000000000 -0500
+++ tagadelic_new/tagadelic.mysql	2006-08-14 10:39:57.000000000 -0400
@@ -0,0 +1,12 @@
+-- 
+-- Table structure for table `tagadelic`
+-- 
+
+CREATE TABLE tagadelic (
+  tid int(11) NOT NULL default '0',
+  name varchar(80) NOT NULL default '',
+  vid int(11) NOT NULL default '0',
+  node_count int(11) NOT NULL default '0',
+  PRIMARY KEY  (tid),
+  KEY count (node_count)
+);
\ No newline at end of file
