aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2016-10-10 09:30:36 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-10-10 09:30:36 +0200
commit1273d82e8b93241a78224c761e17d82dedd51047 (patch)
tree8e4f252d6be87b97afc9a127bd7665171308ad8a /lib/private
parent3f40bb69f8c565a4c32f7452d8845936316377bb (diff)
downloadnextcloud-server-1273d82e8b93241a78224c761e17d82dedd51047.tar.gz
nextcloud-server-1273d82e8b93241a78224c761e17d82dedd51047.zip
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>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/User/Database.php9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/private/User/Database.php b/lib/private/User/Database.php
index eba7beffeae..28cb3302858 100644
--- a/lib/private/User/Database.php
+++ b/lib/private/User/Database.php
@@ -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;
}
/**