diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-07-18 10:06:41 +0200 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-10-20 12:09:06 +0200 |
commit | e0fbd3984003164738ffc9d727314c718867b59e (patch) | |
tree | 176db8d874d8005805396c1323746d0f38083a57 /apps/user_ldap/lib | |
parent | 33be3f754a00d30021ede8a92aae15599b832f4a (diff) | |
download | nextcloud-server-e0fbd3984003164738ffc9d727314c718867b59e.tar.gz nextcloud-server-e0fbd3984003164738ffc9d727314c718867b59e.zip |
Add back runtime cache for intermediate ldap read results
This is a small optimization that save a few LDAP queries
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r-- | apps/user_ldap/lib/Group_LDAP.php | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php index 272ceea5865..5bec38e30ee 100644 --- a/apps/user_ldap/lib/Group_LDAP.php +++ b/apps/user_ldap/lib/Group_LDAP.php @@ -245,8 +245,8 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I if (isset($seen[$dnGroup])) { return []; } - $seen[$dnGroup] = true; $shouldCacheResult = count($seen) === 0; + $seen[$dnGroup] = true; // used extensively in cron job, caching makes sense for nested groups $cacheKey = '_groupMembers' . $dnGroup; @@ -288,7 +288,15 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I } $allMembers = []; - $members = $this->access->readAttribute($dnGroup, $this->access->connection->ldapGroupMemberAssocAttr); + + /** @psalm-var array<string, string[]|bool> $rawMemberReads */ + static $rawMemberReads = []; // runtime cache for intermediate ldap read results + $members = $rawMemberReads[$dnGroup] ?? null; + if ($members === null) { + $members = $this->access->readAttribute($dnGroup, $this->access->connection->ldapGroupMemberAssocAttr); + $rawMemberReads[$dnGroup] = $members; + } + if (is_array($members)) { if ((int)$this->access->connection->ldapNestedGroups === 1) { while ($recordDn = array_shift($members)) { |