diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2020-01-08 14:22:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-08 14:22:04 +0100 |
commit | 8899162463c44c6b22b2b9cee9c3a3d4370bbc7b (patch) | |
tree | de57119de1ba051717a9d2d9da4a53716911a850 | |
parent | 7e95c88c5fa4734099884d3fcb5daa16858aa7db (diff) | |
parent | 79667b58a989ff12887a79c5d484c65a648af97d (diff) | |
download | nextcloud-server-8899162463c44c6b22b2b9cee9c3a3d4370bbc7b.tar.gz nextcloud-server-8899162463c44c6b22b2b9cee9c3a3d4370bbc7b.zip |
Merge pull request #18740 from nextcloud/fix/noid/ldap-better-cache-group-existency
cache group existence early to save useless requests to LDAP
-rw-r--r-- | apps/user_ldap/lib/Access.php | 21 | ||||
-rw-r--r-- | apps/user_ldap/lib/Group_LDAP.php | 2 |
2 files changed, 20 insertions, 3 deletions
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index 059fcbc438c..258222a7f3a 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.php @@ -349,7 +349,7 @@ class Access extends LDAPUtility { } return []; } - + /** * Set password for an LDAP user identified by a DN * @@ -656,6 +656,8 @@ class Access extends LDAPUtility { if ($this->ncUserManager instanceof PublicEmitter && $isUser) { $this->cacheUserExists($name); $this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]); + } elseif (!$isUser) { + $this->cacheGroupExists($name); } return true; } @@ -766,6 +768,13 @@ class Access extends LDAPUtility { } /** + * caches a group as existing + */ + public function cacheGroupExists(string $gid): void { + $this->connection->writeToCache('groupExists'.$gid, true); + } + + /** * caches the user display name * * @param string $ocName the internal Nextcloud username @@ -962,7 +971,15 @@ class Access extends LDAPUtility { * @return array */ public function fetchListOfGroups($filter, $attr, $limit = null, $offset = null) { - return $this->fetchList($this->searchGroups($filter, $attr, $limit, $offset), $this->manyAttributes($attr)); + $groupRecords = $this->searchGroups($filter, $attr, $limit, $offset); + array_walk($groupRecords, function($record) { + $newlyMapped = false; + $gid = $this->dn2ocname($record['dn'][0], null, false, $newlyMapped, $record); + if(!$newlyMapped && is_string($gid)) { + $this->cacheGroupExists($gid); + } + }); + return $this->fetchList($groupRecords, $this->manyAttributes($attr)); } /** diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php index 30d37c13ba2..ec35fc4caef 100644 --- a/apps/user_ldap/lib/Group_LDAP.php +++ b/apps/user_ldap/lib/Group_LDAP.php @@ -1148,7 +1148,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD $uuid, false ); - $this->access->connection->writeToCache("groupExists" . $gid, true); + $this->access->cacheGroupExists($gid); } } return $dn != null; |