diff options
author | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-27 14:53:49 +0000 |
---|---|---|
committer | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-27 14:53:49 +0000 |
commit | e10b9e31e09a6f74132c53504120253a171bfeee (patch) | |
tree | 62980fd206e5317a9505f8abf396f9eee53fb1e6 /engine/lib | |
parent | bc65d839a0d23aaf608801ab0343cdd2bf11a8ba (diff) | |
download | elgg-e10b9e31e09a6f74132c53504120253a171bfeee.tar.gz elgg-e10b9e31e09a6f74132c53504120253a171bfeee.tar.bz2 |
Added mapping to cache username => guid & code => guid. Refs #101.
git-svn-id: https://code.elgg.org/elgg/trunk@1182 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r-- | engine/lib/users.php | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/engine/lib/users.php b/engine/lib/users.php index 60d279ebf..54b79b8e2 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -11,6 +11,12 @@ * @copyright Curverider Ltd 2008
* @link http://elgg.org/
*/
+ + /// Map a username to a cached GUID + $USERNAME_TO_GUID_MAP_CACHE = array(); + + /// Map a user code to a cached GUID + $CODE_TO_GUID_MAP_CACHE = array(); /**
* ElggUser
@@ -656,12 +662,19 @@ */
function get_user_by_username($username)
{
- global $CONFIG;
+ global $CONFIG, $USERNAME_TO_GUID_MAP_CACHE;
+
+ $username = sanitise_string($username); + + // Caching + if ( (isset($USERNAME_TO_GUID_MAP_CACHE[$username])) && (retrieve_cached_entity($USERNAME_TO_GUID_MAP_CACHE[$username])) ) + return retrieve_cached_entity($USERNAME_TO_GUID_MAP_CACHE[$username]); - $username = sanitise_string($username);
$row = get_data_row("SELECT * from {$CONFIG->dbprefix}users_entity where username='$username'");
- if ($row)
- return new ElggUser($row);
+ if ($row) { + $USERNAME_TO_GUID_MAP_CACHE[$username] = $row->guid;
+ return new ElggUser($row); + }
return false;
}
@@ -674,13 +687,19 @@ */
function get_user_by_code($code)
{
- global $CONFIG;
+ global $CONFIG, $CODE_TO_GUID_MAP_CACHE;
+
+ $code = sanitise_string($code); + + // Caching + if ( (isset($CODE_TO_GUID_MAP_CACHE[$code])) && (retrieve_cached_entity($CODE_TO_GUID_MAP_CACHE[$code])) ) + return retrieve_cached_entity($CODE_TO_GUID_MAP_CACHE[$code]); - $code = sanitise_string($code);
$row = get_data_row("SELECT * from {$CONFIG->dbprefix}users_entity where code='$code'");
-
- if ($row)
- return new ElggUser($row);
+ if ($row) { + $CODE_TO_GUID_MAP_CACHE[$code] = $row->guid;
+ return new ElggUser($row); + }
return false;
}
|