Skip to content
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
cache group existence early to save useless requests to LDAP
we do it for users already

Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Jan 8, 2020
commit 79667b58a989ff12887a79c5d484c65a648af97d
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