]> source.dussan.org Git - nextcloud-server.git/commitdiff
remove noise from detectUuid and cache results 19625/head
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Wed, 19 Feb 2020 15:42:36 +0000 (16:42 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Mon, 24 Feb 2020 19:05:58 +0000 (19:05 +0000)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
apps/user_ldap/lib/Access.php

index fcc64ae0dcb6e6e54cbefce8aa07ccb085588313..0cf3e4a91e3713468379d4eb604905c4f23df136 100644 (file)
@@ -1708,13 +1708,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) {
@@ -1723,27 +1729,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;
        }