summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/lib/Group_LDAP.php
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-06-13 18:48:49 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2023-04-27 11:57:45 +0200
commit35dc2235001bf61f07c78b50e74ca029bb9fc05d (patch)
treeb68b7d6e311caf9f7c3cc597e42c085fce792851 /apps/user_ldap/lib/Group_LDAP.php
parent5e96228eb1f7999a327dacab22055ec2aa8e28a3 (diff)
downloadnextcloud-server-35dc2235001bf61f07c78b50e74ca029bb9fc05d.tar.gz
nextcloud-server-35dc2235001bf61f07c78b50e74ca029bb9fc05d.zip
Optimize retrieving display name when searching for users in a group
This is recurrent scenario that we are searching for users and then for each users we fetch the displayName. This is inefficient, so instead try to do one query to fetch everything (e.g. Database backend) or use the already existing DisplayNameCache helper. Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/user_ldap/lib/Group_LDAP.php')
-rw-r--r--apps/user_ldap/lib/Group_LDAP.php17
1 files changed, 13 insertions, 4 deletions
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php
index b32e031175f..ca3a6d13e8f 100644
--- a/apps/user_ldap/lib/Group_LDAP.php
+++ b/apps/user_ldap/lib/Group_LDAP.php
@@ -45,14 +45,15 @@
namespace OCA\User_LDAP;
use Exception;
+use OC\ServerNotAvailableException;
use OCP\Cache\CappedMemoryCache;
use OCP\GroupInterface;
+use OCP\Group\Backend\ABackend;
use OCP\Group\Backend\IDeleteGroupBackend;
use OCP\Group\Backend\IGetDisplayNameBackend;
-use OC\ServerNotAvailableException;
use Psr\Log\LoggerInterface;
-class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, IGetDisplayNameBackend, IDeleteGroupBackend {
+class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDisplayNameBackend, IDeleteGroupBackend {
protected bool $enabled = false;
/** @var CappedMemoryCache<string[]> $cachedGroupMembers array of users with gid as key */
@@ -63,6 +64,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
protected CappedMemoryCache $cachedNestedGroups;
protected GroupPluginManager $groupPluginManager;
protected LoggerInterface $logger;
+ protected Access $access;
/**
* @var string $ldapGroupMemberAssocAttr contains the LDAP setting (in lower case) with the same name
@@ -70,7 +72,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
protected string $ldapGroupMemberAssocAttr;
public function __construct(Access $access, GroupPluginManager $groupPluginManager) {
- parent::__construct($access);
+ $this->access = $access;
$filter = $this->access->connection->ldapGroupFilter;
$gAssoc = $this->access->connection->ldapGroupMemberAssocAttr;
if (!empty($filter) && !empty($gAssoc)) {
@@ -1163,7 +1165,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
* Returns the supported actions as int to be
* compared with GroupInterface::CREATE_GROUP etc.
*/
- public function implementsActions($actions) {
+ public function implementsActions($actions): bool {
return (bool)((GroupInterface::COUNT_USERS |
GroupInterface::DELETE_GROUP |
$this->groupPluginManager->getImplementedActions()) & $actions);
@@ -1331,4 +1333,11 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
$this->access->connection->writeToCache($cacheKey, $displayName);
return $displayName;
}
+
+ public function searchInGroup(string $gid, string $search = '', int $limit = -1, int $offset = 0): array {
+ if (!$this->enabled) {
+ return [];
+ }
+ return parent::searchInGroup($gid, $search, $limit, $offset);
+ }
}