aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/updatenotification/lib/Settings/Admin.php24
-rw-r--r--apps/user_ldap/lib/User_LDAP.php12
-rw-r--r--apps/user_ldap/lib/User_Proxy.php16
3 files changed, 16 insertions, 36 deletions
diff --git a/apps/updatenotification/lib/Settings/Admin.php b/apps/updatenotification/lib/Settings/Admin.php
index 4a74993f0a5..a5f75dc99e6 100644
--- a/apps/updatenotification/lib/Settings/Admin.php
+++ b/apps/updatenotification/lib/Settings/Admin.php
@@ -8,7 +8,6 @@ declare(strict_types=1);
*/
namespace OCA\UpdateNotification\Settings;
-use OC\User\Backend;
use OCA\UpdateNotification\UpdateChecker;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
@@ -20,7 +19,6 @@ use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Settings\ISettings;
use OCP\Support\Subscription\IRegistry;
-use OCP\User\Backend\ICountUsersBackend;
use OCP\Util;
use Psr\Log\LoggerInterface;
@@ -141,26 +139,6 @@ class Admin implements ISettings {
}
private function isWebUpdaterRecommended(): bool {
- return $this->getUserCount() < 100;
- }
-
- /**
- * @see https://github.com/nextcloud/server/blob/39494fbf794d982f6f6551c984e6ca4c4e947d01/lib/private/Support/Subscription/Registry.php#L188-L216 implementation reference
- */
- private function getUserCount(): int {
- $userCount = 0;
- $backends = $this->userManager->getBackends();
- foreach ($backends as $backend) {
- // TODO: change below to 'if ($backend instanceof ICountUsersBackend) {'
- if ($backend->implementsActions(Backend::COUNT_USERS)) {
- /** @var ICountUsersBackend $backend */
- $backendUsers = $backend->countUsers();
- if ($backendUsers !== false) {
- $userCount += $backendUsers;
- }
- }
- }
-
- return $userCount;
+ return (int)$this->userManager->countUsersTotal(100) < 100;
}
}
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;