Index: modules/user/user.module
===================================================================
--- modules/user/user.module	(revision 359)
+++ modules/user/user.module	(working copy)
@@ -139,56 +139,86 @@
  *   cannot be loaded.
  */
 function user_load($array = array()) {
-  // Dynamically compose a SQL query:
-  $query = array();
-  $params = array();
-
-  if (is_numeric($array)) {
-    $array = array('uid' => $array);
-  }
-  elseif (!is_array($array)) {
-    return FALSE;
-  }
-
-  foreach ($array as $key => $value) {
-    if ($key == 'uid' || $key == 'status') {
-      $query[] = "$key = %d";
-      $params[] = $value;
-    }
-    else if ($key == 'pass') {
-      $query[] = "pass = '%s'";
-      $params[] = md5($value);
-    }
-    else {
-      $query[]= "LOWER($key) = LOWER('%s')";
-      $params[] = $value;
-    }
-  }
-  $result = db_query('SELECT * FROM {users} u WHERE '. implode(' AND ', $query), $params);
-
-  if ($user = db_fetch_object($result)) {
-    $user = drupal_unpack($user);
-
-    $user->roles = array();
-    if ($user->uid) {
-      $user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
-    }
-    else {
-      $user->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user';
-    }
-    $result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $user->uid);
-    while ($role = db_fetch_object($result)) {
-      $user->roles[$role->rid] = $role->name;
-    }
-    user_module_invoke('load', $array, $user);
-  }
-  else {
-    $user = FALSE;
-  }
-
-  return $user;
+  
+  static $staticCache = array();
+  
+  // obliczamy klucz w keszu statycznym
+  $cacheKey = serialize($array);
+  
+  // jeśli nie posiadamy informacji zapisanej pod tym kluczem
+  // w keszu statycznym
+  if(!isset($staticCache[$cacheKey])) {
+  	
+  		// tu zapiszemy sobie wynikowy obiekt USER
+  		$res;
+  		
+	  	// to lecimy z całą procedurą obliczającą obiekt USER
+	  	
+  		// Dynamically compose a SQL query:
+	  	$query = array();
+		
+	  	$params = array();
+		
+	  	// flaga, dzieki ktorej ominiemy niefajny "return" w środku kodu 
+	  	$canComputeFlag = TRUE;
+	  	
+		if (is_numeric($array)) {
+		  	$array = array('uid' => $array);
+		} elseif (!is_array($array)) {
+			
+			// w tym miejscu powinnismy wyjsc z funkcji, ale
+			// wtedy obsluga kesza nie będzie bezproblemowa	
+			// korzystamy więc z canCompute'a	
+			$res = FALSE;
+			$canComputeFlag = FALSE;
+			
+		} 
+		
+		if($canComputeFlag) { // wszystko gra
+		
+			foreach ($array as $key => $value) {
+			  	if ($key == 'uid' || $key == 'status') {
+				    $query[] = "$key = %d";
+			    	$params[] = $value;
+			  	} else if ($key == 'pass') {
+				    $query[] = "pass = '%s'";
+			    	$params[] = md5($value);
+			  	} else {
+				    $query[]= "LOWER($key) = LOWER('%s')";
+			    	$params[] = $value;
+			  	}
+			}
+			
+			$result = db_query('SELECT * FROM {users} u WHERE '. implode(' AND ', $query), $params);
+			
+			if ($user = db_fetch_object($result)) {
+				$user = drupal_unpack($user);
+			   	$user->roles = array();
+				if ($user->uid) {
+			  		$user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
+				} else {
+			  		$user->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user';
+				}
+				$result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $user->uid);
+				
+				while ($role = db_fetch_object($result)) {
+			  		$user->roles[$role->rid] = $role->name;
+				}
+				user_module_invoke('load', $array, $user);
+			} else {
+			  $user = FALSE;
+			}
+			$res = $user;
+		}
+		
+		// ustawiamy obiekt w kluczu kesza statycznego
+		$staticCache[$cacheKey] = $res;
+		
+  	}
+  	
+  	// zwracamy to co mamy pod kluczem
+  	return $staticCache[$cacheKey];
 }
-
 /**
  * Save changes to a user account or add a new user.
  *
