Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache group existence early to save useless requests to LDAP #18740

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions apps/user_ldap/lib/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public function extractRangeData($result, $attribute) {
}
return [];
}

/**
* Set password for an LDAP user identified by a DN
*
Expand Down Expand Up @@ -656,6 +656,8 @@ public function mapAndAnnounceIfApplicable(
if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
$this->cacheUserExists($name);
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]);
} elseif (!$isUser) {
$this->cacheGroupExists($name);
}
return true;
}
Expand Down Expand Up @@ -765,6 +767,13 @@ public function cacheUserExists($ocName) {
$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
*
Expand Down Expand Up @@ -962,7 +971,15 @@ public function batchApplyUserAttributes(array $ldapRecords){
* @return array
*/
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));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/Group_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ public function createGroup($gid) {
$uuid,
false
);
$this->access->connection->writeToCache("groupExists" . $gid, true);
$this->access->cacheGroupExists($gid);
}
}
return $dn != null;
Expand Down