Index: admin_menu.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/admin_menu/admin_menu.inc,v
retrieving revision 1.11.2.26
diff -u -r1.11.2.26 admin_menu.inc
--- admin_menu.inc	24 Dec 2009 15:45:50 -0000	1.11.2.26
+++ admin_menu.inc	18 Jan 2011 19:37:20 -0000
@@ -70,13 +70,49 @@
 }
 
 /**
+ * Load a menu link based on a link path.
+ *
+ * Note that this function pre-loads the entire admin menu for efficiency.
+ */
+function admin_menu_link_load($link_path) {
+  return admin_menu_link_cache($link_path);
+}
+
+/**
+ * Function for storing a global cache of all items in the admin menu.
+ *
+ * This function stores and retreives functions based on $link_path. If a link
+ * changes at a particular path during a request, this cache should be updated
+ * by passing the changed link $item back into this function.
+ */
+function admin_menu_link_cache($link_path, $item = NULL) {
+  static $links;
+
+  // Build the initial list of all links in the admin menu.
+  if (!isset($links)) {
+    $links = array();
+    $result = db_query("SELECT menu_name, mlid, plid, link_path, link_title, module, hidden, has_children, weight FROM {menu_links} WHERE menu_name = 'admin_menu'");
+    while ($link = db_fetch_array($result)) {
+      $links[$link['link_path']] = $link;
+    }
+  }
+
+  // Update the link cache if an item has been passed in.
+  if (isset($item)) {
+    $links[$link_path] = $item;
+  }
+
+  return isset($links[$link_path]) ? $links[$link_path] : FALSE;
+}
+
+/**
  * Convenience function that looks up the plid if $item['parent_path'] is set.
  */
 function admin_menu_link_save($item) {
   $item = admin_menu_link_build($item);
 
   // Check whether we are able to update an existing item.
-  $existing_item = db_fetch_array(db_query("SELECT mlid, plid, has_children FROM {menu_links} WHERE link_path = '%s' AND menu_name = '%s'", $item['link_path'], 'admin_menu'));
+  $existing_item = admin_menu_link_load($item['link_path']);
   if ($existing_item) {
     $item['mlid'] = $existing_item['mlid'];
     $item['plid'] = $existing_item['plid'];
@@ -91,14 +127,18 @@
       $item['plid'] = 0;
     }
     else {
-      $plid = db_result(db_query("SELECT mlid from {menu_links} WHERE link_path = '%s' AND menu_name = '%s'", $item['parent_path'], 'admin_menu'));
-      if ($plid) {
-        $item['plid'] = $plid;
+      $parent = admin_menu_link_load($item['parent_path']);
+      if ($parent && $parent['mlid']) {
+        $item['plid'] = $parent['mlid'];
       }
     }
   }
 
-  menu_link_save($item);
+  // If the item is unchanged, don't bother with an update.
+  if (!$existing_item || array_intersect($existing_item, array_intersect($item, $existing_item)) != $existing_item) {
+    menu_link_save($item);
+    admin_menu_link_cache($item['link_path'], $item);
+  }
 }
 
 /**
