Skip to content

Commit 63a23d2

Browse files
authored
Merge pull request #18747 from nextcloud/backport/18740/stable17
[stable17] cache group existence early to save useless requests to LDAP
2 parents 1e37bd2 + 9030897 commit 63a23d2

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

apps/user_ldap/lib/Access.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public function extractRangeData($result, $attribute) {
345345
}
346346
return [];
347347
}
348-
348+
349349
/**
350350
* Set password for an LDAP user identified by a DN
351351
*
@@ -652,6 +652,8 @@ public function mapAndAnnounceIfApplicable(
652652
if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
653653
$this->cacheUserExists($name);
654654
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]);
655+
} elseif (!$isUser) {
656+
$this->cacheGroupExists($name);
655657
}
656658
return true;
657659
}
@@ -761,6 +763,13 @@ public function cacheUserExists($ocName) {
761763
$this->connection->writeToCache('userExists'.$ocName, true);
762764
}
763765

766+
/**
767+
* caches a group as existing
768+
*/
769+
public function cacheGroupExists(string $gid): void {
770+
$this->connection->writeToCache('groupExists'.$gid, true);
771+
}
772+
764773
/**
765774
* caches the user display name
766775
*
@@ -958,7 +967,15 @@ public function batchApplyUserAttributes(array $ldapRecords){
958967
* @return array
959968
*/
960969
public function fetchListOfGroups($filter, $attr, $limit = null, $offset = null) {
961-
return $this->fetchList($this->searchGroups($filter, $attr, $limit, $offset), $this->manyAttributes($attr));
970+
$groupRecords = $this->searchGroups($filter, $attr, $limit, $offset);
971+
array_walk($groupRecords, function($record) {
972+
$newlyMapped = false;
973+
$gid = $this->dn2ocname($record['dn'][0], null, false, $newlyMapped, $record);
974+
if(!$newlyMapped && is_string($gid)) {
975+
$this->cacheGroupExists($gid);
976+
}
977+
});
978+
return $this->fetchList($groupRecords, $this->manyAttributes($attr));
962979
}
963980

964981
/**

apps/user_ldap/lib/Group_LDAP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ public function createGroup($gid) {
11471147
$uuid,
11481148
false
11491149
);
1150-
$this->access->connection->writeToCache("groupExists" . $gid, true);
1150+
$this->access->cacheGroupExists($gid);
11511151
}
11521152
}
11531153
return $dn != null;

0 commit comments

Comments
 (0)