diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-06-17 11:23:03 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-09-05 16:56:47 +0200 |
commit | 3270b7f12ed4efd46bdc8c5bd2d176f1f3547471 (patch) | |
tree | 1ed986eefd4bd3ded9447a0aeea1b6e917baeaf2 /apps/user_ldap | |
parent | e54724728159e96e7f2c24d77a5a22d081f80aac (diff) | |
download | nextcloud-server-3270b7f12ed4efd46bdc8c5bd2d176f1f3547471.tar.gz nextcloud-server-3270b7f12ed4efd46bdc8c5bd2d176f1f3547471.zip |
Add batch methods in user backends
This allows for faster group search with significantly less DB traffic
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r-- | apps/user_ldap/lib/Group_LDAP.php | 6 | ||||
-rw-r--r-- | apps/user_ldap/lib/Group_Proxy.php | 31 |
2 files changed, 35 insertions, 2 deletions
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php index 3a17ba70bb1..b3ff63d3b5c 100644 --- a/apps/user_ldap/lib/Group_LDAP.php +++ b/apps/user_ldap/lib/Group_LDAP.php @@ -48,11 +48,12 @@ 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 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)) { diff --git a/apps/user_ldap/lib/Group_Proxy.php b/apps/user_ldap/lib/Group_Proxy.php index 9d996b45f43..3556be8d125 100644 --- a/apps/user_ldap/lib/Group_Proxy.php +++ b/apps/user_ldap/lib/Group_Proxy.php @@ -31,7 +31,9 @@ namespace OCA\User_LDAP; use OC\ServerNotAvailableException; use OCP\Group\Backend\IDeleteGroupBackend; use OCP\Group\Backend\IGetDisplayNameBackend; +use OCP\Group\Backend\IGroupDetailsBackend; use OCP\Group\Backend\INamedBackend; +use OCP\GroupInterface; class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGetDisplayNameBackend, INamedBackend, IDeleteGroupBackend { private $backends = []; @@ -257,6 +259,21 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet } /** + * {@inheritdoc} + */ + public function getGroupsDetails(array $gids): array { + if (!($this instanceof IGroupDetailsBackend || $this->implementsActions(GroupInterface::GROUP_DETAILS))) { + throw new \Exception("Should not have been called"); + } + + $groupData = []; + foreach ($gids as $gid) { + $groupData[$gid] = $this->handleRequest($gid, 'getGroupDetails', [$gid]); + } + return $groupData; + } + + /** * get a list of all groups * * @return string[] with group names @@ -305,6 +322,20 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet } /** + * {@inheritdoc} + */ + public function groupsExists(array $gids): array { + $existingGroups = []; + foreach ($gids as $gid) { + $exists = $this->handleRequest($gid, 'groupExists', [$gid]); + if ($exists) { + $existingGroups[$gid] = $gid; + } + } + return $existingGroups; + } + + /** * Check if backend implements actions * * @param int $actions bitwise-or'ed actions |