From a6760560c6c6501c5dea3833ffb52a635ef1f621 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 19 Oct 2017 11:03:31 +0200 Subject: [PATCH 1/2] Do not check existance before fetch Signed-off-by: Roeland Jago Douma --- apps/user_ldap/lib/Proxy.php | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/apps/user_ldap/lib/Proxy.php b/apps/user_ldap/lib/Proxy.php index 96bb670b78..805348e777 100644 --- a/apps/user_ldap/lib/Proxy.php +++ b/apps/user_ldap/lib/Proxy.php @@ -169,24 +169,17 @@ abstract class Proxy { * @return mixed|null */ public function getFromCache($key) { - if(is_null($this->cache) || !$this->isCached($key)) { + if($this->cache === null) { return null; } + $key = $this->getCacheKey($key); - - return json_decode(base64_decode($this->cache->get($key))); - } - - /** - * @param string $key - * @return bool - */ - public function isCached($key) { - if(is_null($this->cache)) { - return false; + $value = $this->cache->get($key); + if ($value === null) { + return null; } - $key = $this->getCacheKey($key); - return $this->cache->hasKey($key); + + return json_decode(base64_decode($value)); } /** From 4388ec22316a44d658593eb11b4d51eaa4183006 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 19 Oct 2017 11:05:24 +0200 Subject: [PATCH 2/2] Little bit of code cleanup Signed-off-by: Roeland Jago Douma --- apps/user_ldap/lib/Proxy.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/user_ldap/lib/Proxy.php b/apps/user_ldap/lib/Proxy.php index 805348e777..305d2c4181 100644 --- a/apps/user_ldap/lib/Proxy.php +++ b/apps/user_ldap/lib/Proxy.php @@ -65,7 +65,7 @@ abstract class Proxy { static $db; static $coreUserManager; static $coreNotificationManager; - if(is_null($fs)) { + if($fs === null) { $ocConfig = \OC::$server->getConfig(); $fs = new FilesystemHelper(); $log = new LogWrapper(); @@ -158,7 +158,7 @@ abstract class Proxy { */ private function getCacheKey($key) { $prefix = 'LDAP-Proxy-'; - if(is_null($key)) { + if($key === null) { return $prefix; } return $prefix.md5($key); @@ -187,16 +187,16 @@ abstract class Proxy { * @param mixed $value */ public function writeToCache($key, $value) { - if(is_null($this->cache)) { + if($this->cache === null) { return; } $key = $this->getCacheKey($key); $value = base64_encode(json_encode($value)); - $this->cache->set($key, $value, '2592000'); + $this->cache->set($key, $value, 2592000); } public function clearCache() { - if(is_null($this->cache)) { + if($this->cache === null) { return; } $this->cache->clear($this->getCacheKey(null));