Index: user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.892.2.27
diff -u -p -r1.892.2.27 user.module
--- user.module	6 Aug 2010 11:58:09 -0000	1.892.2.27
+++ user.module	20 Sep 2010 21:32:17 -0000
@@ -133,12 +133,20 @@ function user_external_login($account, $
  * @param $array
  *   An associative array of attributes to search for in selecting the
  *   user, such as user name or e-mail address.
+ * @param $reset = FALSE
+ *   (optional) If set, drop current static cache.
  *
  * @return
  *   A fully-loaded $user object upon successful user load or FALSE if user
  *   cannot be loaded.
  */
-function user_load($array = array()) {
+function user_load($array = array(), $reset = FALSE) {
+  static $cache;
+
+  if ($reset || !is_array($cache)) {
+    $cache = array('uid' => array(), 'name' => array());
+  }
+
   // Dynamically compose a SQL query:
   $query = array();
   $params = array();
@@ -150,6 +158,16 @@ function user_load($array = array()) {
     return FALSE;
   }
 
+  if (count($array) == 1) {
+    list($key, $value) = each($array);
+    if ($key == 'uid' || $key == 'name') {
+      $value = is_string($value) ? strtolower($value) : $value;
+      if (array_key_exists($value, $cache)) {
+        return $cache[$value];
+      }
+    }
+  }
+
   foreach ($array as $key => $value) {
     if ($key == 'uid' || $key == 'status') {
       $query[] = "$key = %d";
@@ -160,8 +178,8 @@ function user_load($array = array()) {
       $params[] = md5($value);
     }
     else {
-      $query[]= "LOWER($key) = LOWER('%s')";
-      $params[] = $value;
+      $query[]= "LOWER($key) = '%s'";
+      $params[] = strtolower($value);
     }
   }
   $result = db_query('SELECT * FROM {users} u WHERE '. implode(' AND ', $query), $params);
@@ -181,6 +199,8 @@ function user_load($array = array()) {
       $user->roles[$role->rid] = $role->name;
     }
     user_module_invoke('load', $array, $user);
+    $cache[$user->uid] = $user;
+    $cache[strtolower($user->name)] = $user;
   }
   else {
     $user = FALSE;
