diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2025-01-14 12:26:24 +0100 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2025-01-14 12:26:24 +0100 |
commit | e187e4e87f73b6b17e40248d8779b8defe139a90 (patch) | |
tree | 34d2eb305e9ecdf59e77e5df6878c2c820a79d92 /apps/user_ldap | |
parent | dffab2221de12a02eb0a6789b1321f203ac93e3a (diff) | |
download | nextcloud-server-e187e4e87f73b6b17e40248d8779b8defe139a90.tar.gz nextcloud-server-e187e4e87f73b6b17e40248d8779b8defe139a90.zip |
feat(updatenotification): Add a limit to user count from LDAP so save performances
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r-- | apps/user_ldap/lib/User_LDAP.php | 12 | ||||
-rw-r--r-- | apps/user_ldap/lib/User_Proxy.php | 16 |
2 files changed, 15 insertions, 13 deletions
diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php index 6970a52d3d7..60d7b7e92c2 100644 --- a/apps/user_ldap/lib/User_LDAP.php +++ b/apps/user_ldap/lib/User_LDAP.php @@ -17,12 +17,12 @@ use OCA\User_LDAP\User\User; use OCP\IUserBackend; use OCP\Notification\IManager as INotificationManager; use OCP\User\Backend\ICountMappedUsersBackend; -use OCP\User\Backend\ICountUsersBackend; +use OCP\User\Backend\ILimitAwareCountUsersBackend; use OCP\User\Backend\IProvideEnabledStateBackend; use OCP\UserInterface; use Psr\Log\LoggerInterface; -class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, IUserLDAP, ICountUsersBackend, ICountMappedUsersBackend, IProvideEnabledStateBackend { +class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, IUserLDAP, ILimitAwareCountUsersBackend, ICountMappedUsersBackend, IProvideEnabledStateBackend { public function __construct( Access $access, protected INotificationManager $notificationManager, @@ -528,20 +528,18 @@ class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, I /** * counts the users in LDAP - * - * @return int|false */ - public function countUsers() { + public function countUsers(int $limit = 0): int|false { if ($this->userPluginManager->implementsActions(Backend::COUNT_USERS)) { return $this->userPluginManager->countUsers(); } $filter = $this->access->getFilterForUserCount(); - $cacheKey = 'countUsers-' . $filter; + $cacheKey = 'countUsers-' . $filter . '-' . $limit; if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { return $entries; } - $entries = $this->access->countUsers($filter); + $entries = $this->access->countUsers($filter, limit:$limit); $this->access->connection->writeToCache($cacheKey, $entries); return $entries; } diff --git a/apps/user_ldap/lib/User_Proxy.php b/apps/user_ldap/lib/User_Proxy.php index 7786b8f0497..5079830b83c 100644 --- a/apps/user_ldap/lib/User_Proxy.php +++ b/apps/user_ldap/lib/User_Proxy.php @@ -13,12 +13,12 @@ use OCA\User_LDAP\User\User; use OCP\IUserBackend; use OCP\Notification\IManager as INotificationManager; use OCP\User\Backend\ICountMappedUsersBackend; -use OCP\User\Backend\ICountUsersBackend; +use OCP\User\Backend\ILimitAwareCountUsersBackend; use OCP\User\Backend\IProvideEnabledStateBackend; use OCP\UserInterface; use Psr\Log\LoggerInterface; -class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP, ICountUsersBackend, ICountMappedUsersBackend, IProvideEnabledStateBackend { +class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP, ILimitAwareCountUsersBackend, ICountMappedUsersBackend, IProvideEnabledStateBackend { /** @var User_LDAP[] */ private array $backends = []; private ?User_LDAP $refBackend = null; @@ -350,17 +350,21 @@ class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP /** * Count the number of users - * - * @return int|false */ - public function countUsers() { + public function countUsers(int $limit = 0): int|false { $this->setup(); $users = false; foreach ($this->backends as $backend) { - $backendUsers = $backend->countUsers(); + $backendUsers = $backend->countUsers($limit); if ($backendUsers !== false) { $users = (int)$users + $backendUsers; + if ($limit > 0) { + if ($users >= $limit) { + break; + } + $limit -= $users; + } } } return $users; |