Commit d750902a authored by Leigh Stoller's avatar Leigh Stoller

Improvements to user/project caching.

parent 0039e166
......@@ -84,7 +84,12 @@ class Project
# Backwards compatable lookup by pid. Will eventually flush this.
function LookupByPid($pid) {
$safe_pid = addslashes($pid);
global $project_cache;
# Look in cache first
if (array_key_exists($pid, $project_cache))
return $project_cache[$pid];
$query_result =
DBQueryWarn("select pid_idx from projects where pid='$safe_pid'");
......@@ -96,8 +101,11 @@ class Project
$foo = new Project($idx);
if ($foo->IsValid())
if ($foo->IsValid()) {
# Insert into cache.
$project_cache[$pid] = $foo;
return $foo;
}
return null;
}
......
......@@ -95,15 +95,21 @@ class User
return $foo;
}
# Insert into cache.
$user_cache["$uid_idx"] =& $foo;
$user_cache["$uid_idx"] =& $foo;
$user_cache[$foo->uid()] =& $foo;
return $foo;
}
# Backwards compatable lookup by uid. Will eventually flush this.
function LookupByUid($uid) {
global $user_cache;
$safe_uid = addslashes($uid);
$status_archived = TBDB_USERSTATUS_ARCHIVED;
# Look in cache first
if (array_key_exists("$uid", $user_cache))
return $user_cache["$uid"];
$query_result =
DBQueryWarn("select uid_idx from users ".
"where uid='$safe_uid' and ".
......@@ -711,6 +717,9 @@ class User
if (array_key_exists("$uid_idx", $user_cache))
unset($user_cache["$uid_idx"]);
if (array_key_exists($this->uid(), $user_cache))
unset($user_cache[$this->uid()]);
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment