summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2020-01-08 11:02:37 +0100
committerBackportbot <backportbot-noreply@rullzer.com>2020-01-08 13:22:59 +0000
commit903089793362a64294e934bbefd4608bd14f74e9 (patch)
treef41ebd73051ec17bfa1a9f1280163f04de33d4d1 /apps
parentd92be82000053acb5fca29072ea631ea06292c26 (diff)
downloadnextcloud-server-903089793362a64294e934bbefd4608bd14f74e9.tar.gz
nextcloud-server-903089793362a64294e934bbefd4608bd14f74e9.zip
cache group existence early to save useless requests to LDAP
we do it for users already Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps')
-rw-r--r--apps/user_ldap/lib/Access.php21
-rw-r--r--apps/user_ldap/lib/Group_LDAP.php2
2 files changed, 20 insertions, 3 deletions
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php
index 6104c908a84..fcc64ae0dcb 100644
--- a/apps/user_ldap/lib/Access.php
+++ b/apps/user_ldap/lib/Access.php
@@ -345,7 +345,7 @@ class Access extends LDAPUtility {
}
return [];
}
-
+
/**
* Set password for an LDAP user identified by a DN
*
@@ -652,6 +652,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;
}
@@ -762,6 +764,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
@@ -958,7 +967,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 0a348c2ee64..0c4b7182ec4 100644
--- a/apps/user_ldap/lib/Group_LDAP.php
+++ b/apps/user_ldap/lib/Group_LDAP.php
@@ -1147,7 +1147,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;