Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.330.2.7
diff -U3 -r1.330.2.7 taxonomy.module
--- modules/taxonomy/taxonomy.module	17 Jun 2007 02:00:51 -0000	1.330.2.7
+++ modules/taxonomy/taxonomy.module	19 Jun 2007 16:49:52 -0000
@@ -918,17 +918,29 @@
  * Find all parents of a given term ID.
  */
 function taxonomy_get_parents($tid, $key = 'tid') {
+  static $cached_parents = 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($cached_parents[$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;
+      }
+      $cached_parents[$tid] = $parents;
     }
-    return $parents;
   }
   else {
     return array();
   }
+
+  // Prevent changing of the cached objects by other functions
+  $return = array();
+  foreach($cached_parents[$tid] as $key => $value) {
+    $return[$key] = drupal_clone($value);
+  }
+
+  return $return;
 }

 /**
@@ -951,17 +963,31 @@
  * Find all children of a term ID.
  */
 function taxonomy_get_children($tid, $vid = 0, $key = 'tid') {
-  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);
+  static $cached_children = array();
+
+  if (!isset($cached_children[$vid])) {
+    $cached_children[$vid] = array();
   }
-  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);
+
+  if (!isset($cached_children[$vid][$tid])) {
+    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);
+    }
+    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);
+    }
+    $cached_children[$vid][$tid] = array();
+    while ($term = db_fetch_object($result)) {
+      $cached_children[$vid][$tid][$term->$key] = $term;
+    }
   }
-  $children = array();
-  while ($term = db_fetch_object($result)) {
-    $children[$term->$key] = $term;
+
+  // Prevent changing of the cached objects by other functions
+  $return = array();
+  foreach($cached_children[$vid][$tid] as $key => $value) {
+    $return[$key] = drupal_clone($value);
   }
-  return $children;
+  return $return;
 }

 /**
