From 9e1dd52c998ed7c9feb6ba9a1a64f0c6856fd8fa Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Thu, 17 Nov 2022 15:12:24 +0100 Subject: Cache the fetched list of groups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/user_ldap/lib/Access.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'apps/user_ldap') 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 -- cgit v1.2.3 From 723c1b8adc4337dbbcf2598cf37bf37b099eb148 Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Mon, 19 Dec 2022 11:59:45 +0100 Subject: Fix user_ldap tests now that list of groups gets cached MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/user_ldap/tests/AccessTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/user_ldap') 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); -- cgit v1.2.3