summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorCôme Chilliet <91878298+come-nc@users.noreply.github.com>2022-12-19 12:34:05 +0100
committerGitHub <noreply@github.com>2022-12-19 12:34:05 +0100
commit75e369d3069fea662af7ef41378f8ef4460e3ce1 (patch)
treeb5609e68c1749f507741a048c66f1d521cabd205 /apps/user_ldap
parent1bae41ccecfb45b72e745f35e9eda73de32d0f28 (diff)
parent723c1b8adc4337dbbcf2598cf37bf37b099eb148 (diff)
downloadnextcloud-server-75e369d3069fea662af7ef41378f8ef4460e3ce1.tar.gz
nextcloud-server-75e369d3069fea662af7ef41378f8ef4460e3ce1.zip
Merge pull request #35231 from nextcloud/fix/user_ldap-cache-fetched-list-of-groups
Cache the fetched list of groups
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/lib/Access.php21
-rw-r--r--apps/user_ldap/tests/AccessTest.php2
2 files changed, 15 insertions, 8 deletions
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php
index a64c61f8139..6b12e0edc11 100644
--- a/apps/user_ldap/lib/Access.php
+++ b/apps/user_ldap/lib/Access.php
@@ -917,6 +917,11 @@ class Access extends LDAPUtility {
* @return array[]
*/
public function fetchListOfGroups(string $filter, array $attr, int $limit = null, int $offset = null): array {
+ $cacheKey = 'fetchListOfGroups_' . $filter . '_' . implode('-', $attr) . '_' . (string)$limit . '_' . (string)$offset;
+ $listOfGroups = $this->connection->getFromCache($cacheKey);
+ if (!is_null($listOfGroups)) {
+ return $listOfGroups;
+ }
$groupRecords = $this->searchGroups($filter, $attr, $limit, $offset);
$listOfDNs = array_reduce($groupRecords, function ($listOfDNs, $entry) {
@@ -935,7 +940,9 @@ class Access extends LDAPUtility {
$this->cacheGroupExists($gid);
}
});
- return $this->fetchList($groupRecords, $this->manyAttributes($attr));
+ $listOfGroups = $this->fetchList($groupRecords, $this->manyAttributes($attr));
+ $this->connection->writeToCache($cacheKey, $listOfGroups);
+ return $listOfGroups;
}
private function fetchList(array $list, bool $manyAttributes): array {
@@ -1985,12 +1992,12 @@ class Access extends LDAPUtility {
}
$this->logger->debug('Ready for a paged search', ['app' => 'user_ldap']);
return [true, $pageSize, $this->lastCookie];
- /* ++ Fixing RHDS searches with pages with zero results ++
- * We couldn't get paged searches working with our RHDS for login ($limit = 0),
- * due to pages with zero results.
- * So we added "&& !empty($this->lastCookie)" to this test to ignore pagination
- * if we don't have a previous paged search.
- */
+ /* ++ Fixing RHDS searches with pages with zero results ++
+ * We couldn't get paged searches working with our RHDS for login ($limit = 0),
+ * due to pages with zero results.
+ * So we added "&& !empty($this->lastCookie)" to this test to ignore pagination
+ * if we don't have a previous paged search.
+ */
} elseif ($this->lastCookie !== '') {
// a search without limit was requested. However, if we do use
// Paged Search once, we always must do it. This requires us to
diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php
index c2902a67766..ce05839c842 100644
--- a/apps/user_ldap/tests/AccessTest.php
+++ b/apps/user_ldap/tests/AccessTest.php
@@ -678,7 +678,7 @@ class AccessTest extends TestCase {
$this->groupMapper->expects($this->never())
->method('getNameByDN');
- $this->connection->expects($this->exactly(2))
+ $this->connection->expects($this->exactly(3))
->method('writeToCache');
$groups = $this->access->fetchListOfGroups($filter, $attributes);