Merge pull request #1672 from nextcloud/cache_non_exisiting_db_user
Cache non existing DB user
This commit is contained in:
commit
2dcd97bf14
|
@ -94,6 +94,9 @@ class Database extends Backend implements IUserBackend {
|
||||||
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )');
|
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )');
|
||||||
$result = $query->execute(array($uid, \OC::$server->getHasher()->hash($password)));
|
$result = $query->execute(array($uid, \OC::$server->getHasher()->hash($password)));
|
||||||
|
|
||||||
|
// Clear cache
|
||||||
|
unset($this->cache[$uid]);
|
||||||
|
|
||||||
return $result ? true : false;
|
return $result ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,7 +237,7 @@ class Database extends Backend implements IUserBackend {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
private function loadUser($uid) {
|
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(?)');
|
$query = \OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` WHERE LOWER(`uid`) = LOWER(?)');
|
||||||
$result = $query->execute(array($uid));
|
$result = $query->execute(array($uid));
|
||||||
|
|
||||||
|
@ -243,6 +246,8 @@ class Database extends Backend implements IUserBackend {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->cache[$uid] = false;
|
||||||
|
|
||||||
while ($row = $result->fetchRow()) {
|
while ($row = $result->fetchRow()) {
|
||||||
$this->cache[$uid]['uid'] = $row['uid'];
|
$this->cache[$uid]['uid'] = $row['uid'];
|
||||||
$this->cache[$uid]['displayname'] = $row['displayname'];
|
$this->cache[$uid]['displayname'] = $row['displayname'];
|
||||||
|
@ -284,7 +289,7 @@ class Database extends Backend implements IUserBackend {
|
||||||
*/
|
*/
|
||||||
public function userExists($uid) {
|
public function userExists($uid) {
|
||||||
$this->loadUser($uid);
|
$this->loadUser($uid);
|
||||||
return !empty($this->cache[$uid]);
|
return $this->cache[$uid] !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue