Cache non existing DB user
We always query the database backend. Even if we use a different one (ldap for example). Now we do this everytime we try to get a user object so caching that a user is not in the DB safes some queries on each request then (at least 2 what I found). Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
3f40bb69f8
commit
1273d82e8b
|
@ -94,6 +94,9 @@ class Database extends Backend implements IUserBackend {
|
|||
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )');
|
||||
$result = $query->execute(array($uid, \OC::$server->getHasher()->hash($password)));
|
||||
|
||||
// Clear cache
|
||||
unset($this->cache[$uid]);
|
||||
|
||||
return $result ? true : false;
|
||||
}
|
||||
|
||||
|
@ -234,7 +237,7 @@ class Database extends Backend implements IUserBackend {
|
|||
* @return boolean
|
||||
*/
|
||||
private function loadUser($uid) {
|
||||
if (empty($this->cache[$uid])) {
|
||||
if (!isset($this->cache[$uid])) {
|
||||
$query = \OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` WHERE LOWER(`uid`) = LOWER(?)');
|
||||
$result = $query->execute(array($uid));
|
||||
|
||||
|
@ -243,6 +246,8 @@ class Database extends Backend implements IUserBackend {
|
|||
return false;
|
||||
}
|
||||
|
||||
$this->cache[$uid] = false;
|
||||
|
||||
while ($row = $result->fetchRow()) {
|
||||
$this->cache[$uid]['uid'] = $row['uid'];
|
||||
$this->cache[$uid]['displayname'] = $row['displayname'];
|
||||
|
@ -284,7 +289,7 @@ class Database extends Backend implements IUserBackend {
|
|||
*/
|
||||
public function userExists($uid) {
|
||||
$this->loadUser($uid);
|
||||
return !empty($this->cache[$uid]);
|
||||
return $this->cache[$uid] !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue