Skip to content

Commit

Permalink
Merge pull request #1672 from nextcloud/cache_non_exisiting_db_user
Browse files Browse the repository at this point in the history
Cache non existing DB user
  • Loading branch information
rullzer authored Oct 10, 2016
2 parents a0cb809 + 1273d82 commit 2dcd97b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/private/User/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public function createUser($uid, $password) {
$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;
}

Expand Down Expand Up @@ -234,7 +237,7 @@ public function checkPassword($uid, $password) {
* @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));

Expand All @@ -243,6 +246,8 @@ private function loadUser($uid) {
return false;
}

$this->cache[$uid] = false;

while ($row = $result->fetchRow()) {
$this->cache[$uid]['uid'] = $row['uid'];
$this->cache[$uid]['displayname'] = $row['displayname'];
Expand Down Expand Up @@ -284,7 +289,7 @@ public function getUsers($search = '', $limit = null, $offset = null) {
*/
public function userExists($uid) {
$this->loadUser($uid);
return !empty($this->cache[$uid]);
return $this->cache[$uid] !== false;
}

/**
Expand Down

0 comments on commit 2dcd97b

Please sign in to comment.