Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.330.2.6
diff -U3 -r1.330.2.6 taxonomy.module
--- modules/taxonomy/taxonomy.module	7 May 2007 03:15:44 -0000	1.330.2.6
+++ modules/taxonomy/taxonomy.module	7 May 2007 18:52:11 -0000
@@ -904,17 +904,23 @@
  * Find all parents of a given term ID.
  */
 function taxonomy_get_parents($tid, $key = 'tid') {
+  static $cache = array();
+
   if ($tid) {
-    $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.parent = t.tid WHERE h.tid = %d ORDER BY weight, name', 't', 'tid'), $tid);
-    $parents = array();
-    while ($parent = db_fetch_object($result)) {
-      $parents[$parent->$key] = $parent;
+    if (!isset($cache[$tid])) {
+      $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.parent = t.tid WHERE h.tid = %d ORDER BY weight, name', 't', 'tid'), $tid);
+      $parents = array();
+      while ($parent = db_fetch_object($result)) {
+        $parents[$parent->$key] = $parent;
+      }
+      $cache[$tid] = $parents;
     }
-    return $parents;
   }
   else {
     return array();
   }
+
+  return $cache[$tid];
 }

 /**
@@ -937,17 +943,32 @@
  * Find all children of a term ID.
  */
 function taxonomy_get_children($tid, $vid = 0, $key = 'tid') {
+  static $cache = array();
+  static $vidcache = array();
+
   if ($vid) {
-    $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.tid = t.tid WHERE t.vid = %d AND h.parent = %d ORDER BY weight, name', 't', 'tid'), $vid, $tid);
+    if (!isset($vidcache[$vid][$tid])) {
+      if (!isset($vidcache[$vid])) {
+        $vidcache[$vid] = array();
+      }
+      $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.tid = t.tid WHERE t.vid = %d AND h.parent = %d ORDER BY weight, name', 't', 'tid'), $vid, $tid);
+      $vidcache[$vid][$tid] = array();
+      while ($term = db_fetch_object($result)) {
+        $vidcache[$vid][$tid][$term->$key] = $term;
+      }
+    }
+    return $vidcache[$vid][$tid];
   }
   else {
-    $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.tid = t.tid WHERE parent = %d ORDER BY weight, name', 't', 'tid'), $tid);
-  }
-  $children = array();
-  while ($term = db_fetch_object($result)) {
-    $children[$term->$key] = $term;
+    if (!isset($cache[$tid])) {
+      $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.tid = t.tid WHERE parent = %d ORDER BY weight, name', 't', 'tid'), $tid);
+      $cache[$tid] = array();
+      while ($term = db_fetch_object($result)) {
+        $cache[$tid][$term->$key] = $term;
+      }
+    }
+    return $cache[$tid];
   }
-  return $children;
 }

 /**
