mirror of
https://github.com/nextcloud/server.git
synced 2026-06-12 10:10:49 -04:00
Merge pull request #35231 from nextcloud/fix/user_ldap-cache-fetched-list-of-groups
Cache the fetched list of groups
This commit is contained in:
commit
75e369d306
2 changed files with 15 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue