'searchUsers' executes slowly with ldapquery
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 36.9k
- Forks
- 5.2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 713
Description
there a lot of groups、members in my AD, when i debug code ,i find displayNamesInGroup execution takes too long,should we change this function, do not get all displayname then filter. i suggest change this ,
1.get groupdn by gid
2.get users by filter with -searchBase or groupdn
* get a list of all display names in a group
*
* @param string $gid
* @param string $search
* @param int $limit
* @param int $offset
* @return array an array of display names (value) and user ids (key)
*/
public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$group = $this->get($gid);
if (is_null($group)) {
return [];
}
$search = trim($search);
$groupUsers = [];
if (!empty($search)) {
// only user backends have the capability to do a complex search for users
$searchOffset = 0;
$searchLimit = $limit * 100;
if ($limit === -1) {
$searchLimit = 500;
}
do {
$filteredUsers = $this->userManager->searchDisplayName($search, $searchLimit, $searchOffset);
foreach ($filteredUsers as $filteredUser) {
if ($group->inGroup($filteredUser)) {
$groupUsers[] = $filteredUser;
}
}
$searchOffset += $searchLimit;
} while (count($groupUsers) < $searchLimit + $offset && count($filteredUsers) >= $searchLimit);
if ($limit === -1) {
$groupUsers = array_slice($groupUsers, $offset);
} else {
$groupUsers = array_slice($groupUsers, $offset, $limit);
}
} else {
$groupUsers = $group->searchUsers('', $limit, $offset);
}
$matchingUsers = [];
foreach ($groupUsers as $groupUser) {
$matchingUsers[(string) $groupUser->getUID()] = $groupUser->getDisplayName();
}
return $matchingUsers;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the displayNamesInGroup function shown in the issue and trace its get, searchDisplayName, inGroup, and searchUsers calls. Reproduce the slow path with a large Active Directory group, then verify that lookup filtering avoids fetching all display names while preserving search, limit, and offset behavior. No test file or source path is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- authentication, backend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100