Merge pull request #18747 from nextcloud/backport/18740/stable17

[stable17] cache group existence early to save useless requests to LDAP
This commit is contained in:
blizzz 2020-01-08 16:20:27 +01:00 committed by GitHub
commit 63a23d229e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View file

@ -652,6 +652,8 @@ class Access extends LDAPUtility {
if ($this->ncUserManager instanceof PublicEmitter && $isUser) { if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
$this->cacheUserExists($name); $this->cacheUserExists($name);
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]); $this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]);
} elseif (!$isUser) {
$this->cacheGroupExists($name);
} }
return true; return true;
} }
@ -761,6 +763,13 @@ class Access extends LDAPUtility {
$this->connection->writeToCache('userExists'.$ocName, true); $this->connection->writeToCache('userExists'.$ocName, true);
} }
/**
* caches a group as existing
*/
public function cacheGroupExists(string $gid): void {
$this->connection->writeToCache('groupExists'.$gid, true);
}
/** /**
* caches the user display name * caches the user display name
* *
@ -958,7 +967,15 @@ class Access extends LDAPUtility {
* @return array * @return array
*/ */
public function fetchListOfGroups($filter, $attr, $limit = null, $offset = null) { public function fetchListOfGroups($filter, $attr, $limit = null, $offset = null) {
return $this->fetchList($this->searchGroups($filter, $attr, $limit, $offset), $this->manyAttributes($attr)); $groupRecords = $this->searchGroups($filter, $attr, $limit, $offset);
array_walk($groupRecords, function($record) {
$newlyMapped = false;
$gid = $this->dn2ocname($record['dn'][0], null, false, $newlyMapped, $record);
if(!$newlyMapped && is_string($gid)) {
$this->cacheGroupExists($gid);
}
});
return $this->fetchList($groupRecords, $this->manyAttributes($attr));
} }
/** /**

View file

@ -1147,7 +1147,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
$uuid, $uuid,
false false
); );
$this->access->connection->writeToCache("groupExists" . $gid, true); $this->access->cacheGroupExists($gid);
} }
} }
return $dn != null; return $dn != null;