From 3200eedc4cabb1cc59e77939c8b7ae5d4e283774 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 19 Feb 2020 16:42:36 +0100 Subject: [PATCH] remove noise from detectUuid and cache results Signed-off-by: Arthur Schiwon --- apps/user_ldap/lib/Access.php | 42 +++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index 64ee172a8b..3ebd053402 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.php @@ -1676,13 +1676,19 @@ class Access extends LDAPUtility { $uuidOverride = $this->connection->ldapExpertUUIDGroupAttr; } - if(($this->connection->$uuidAttr !== 'auto') && !$force) { - return true; - } + if(!$force) { + if($this->connection->$uuidAttr !== 'auto') { + return true; + } else if (is_string($uuidOverride) && trim($uuidOverride) !== '') { + $this->connection->$uuidAttr = $uuidOverride; + return true; + } - if (is_string($uuidOverride) && trim($uuidOverride) !== '' && !$force) { - $this->connection->$uuidAttr = $uuidOverride; - return true; + $attribute = $this->connection->getFromCache($uuidAttr); + if(!$attribute === null) { + $this->connection->$uuidAttr = $attribute; + return true; + } } foreach(self::UUID_ATTRIBUTES as $attribute) { @@ -1691,27 +1697,29 @@ class Access extends LDAPUtility { if(isset($ldapRecord[$attribute])) { $this->connection->$uuidAttr = $attribute; return true; - } else { - continue; } + continue; } $value = $this->readAttribute($dn, $attribute); if(is_array($value) && isset($value[0]) && !empty($value[0])) { - \OCP\Util::writeLog( - 'user_ldap', - 'Setting '.$attribute.' as '.$uuidAttr, - ILogger::DEBUG + \OC::$server->getLogger()->debug( + 'Setting {attribute} as {subject}', + [ + 'app' => 'user_ldap', + 'attribute' => $attribute, + 'subject' => $uuidAttr + ] ); $this->connection->$uuidAttr = $attribute; + $this->connection->writeToCache($uuidAttr, $attribute); return true; + } elseif ($value === false) { + // record not available + return false; } } - \OCP\Util::writeLog( - 'user_ldap', - 'Could not autodetect the UUID attribute', - ILogger::ERROR - ); + \OC::$server->getLogger()->debug('Could not autodetect the UUID attribute', ['app' => 'user_ldap']); return false; }