--- modules/user/user.module 2006-07-16 16:48:05.000000000 -0400 +++ modules/user/user.module 2006-07-16 17:39:05.000000000 -0400 @@ -47,42 +47,56 @@ function user_load($array = array()) { $query = array(); $params = array(); - 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); - } + // object based caching -- ensure that the uid value is present since it is the cache key + global $object_cache; + if($object_cache && array_key_exists('uid', $array)) { + $user = cache_get('user:' . $array['uid'])->data; + $user = unserialize($user); + } + // if the cache retrned nothing, then load the $user normally + if(!isset($user->uid)) { + 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 (db_num_rows($result)) { + $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); + + // set the cached user object + if ($object_cache) { + cache_set('user:' .$user->uid, serialize($user), CACHE_PERMANENT, NULL); + } + } else { - $query[]= "LOWER($key) = LOWER('%s')"; - $params[] = $value; + $user = FALSE; } } - $result = db_query('SELECT * FROM {users} u WHERE ' . implode(' AND ', $query), $params); - - if (db_num_rows($result)) { - $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; } @@ -105,6 +119,12 @@ function user_save($account, $array = ar // Dynamically compose a SQL query: $user_fields = user_fields(); if ($account->uid) { + // object based caching -- destroy the current cached $user + global $object_cache; + if ($object_cache) { + cache_clear_all('user:' .$account->uid); + $object_cache = FALSE; + } user_module_invoke('update', $array, $account, $category); $data = unserialize(db_result(db_query('SELECT data FROM {users} WHERE uid = %d', $account->uid))); @@ -193,6 +213,11 @@ function user_save($account, $array = ar // Build the initial user object. $user = user_load(array('uid' => $array['uid'])); + // object based caching -- don't load from cache + if ($object_cache) { + $object_cache = FALSE; + } + user_module_invoke('insert', $array, $user, $category); // Build and save the serialized data field now @@ -228,7 +253,7 @@ function user_save($account, $array = ar if (sizeof($authmaps) > 0) { user_set_authmaps($user, $authmaps); } - + return $user; }