aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2025-03-26 21:03:53 +0100
committerAndy Scherzinger <info@andy-scherzinger.de>2025-03-30 08:54:41 +0200
commit275b32d5138c0221b425198a9b517f536bba0a0a (patch)
tree319dddb06b6b4148ad6d5da3e73dddc469eeef28 /lib
parentefa7d59ce9ccb895648c809d95a553c09546b42a (diff)
downloadnextcloud-server-275b32d5138c0221b425198a9b517f536bba0a0a.tar.gz
nextcloud-server-275b32d5138c0221b425198a9b517f536bba0a0a.zip
feat: Implement getSeenUsers to iterate over users
This method uses an iterator. This is lighter on resources and gives more control to the caller Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/User/Manager.php26
-rw-r--r--lib/public/IUserManager.php11
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php
index 62a7b39be16..cfe2d6dad0b 100644
--- a/lib/private/User/Manager.php
+++ b/lib/private/User/Manager.php
@@ -827,4 +827,30 @@ class Manager extends PublicEmitter implements IUserManager {
public function getDisplayNameCache(): DisplayNameCache {
return $this->displayNameCache;
}
+
+ /**
+ * Gets the list of users sorted by lastLogin, from most recent to least recent
+ *
+ * @param int $offset from which offset to fetch
+ * @return \Iterator<IUser> list of user IDs
+ * @since 30.0.0
+ */
+ public function getSeenUsers(int $offset = 0): \Iterator {
+ $limit = 1000;
+
+ do {
+ $userIds = $this->getSeenUserIds($limit, $offset);
+ $offset += $limit;
+
+ foreach ($userIds as $userId) {
+ foreach ($this->backends as $backend) {
+ if ($backend->userExists($userId)) {
+ $user = $this->getUserObject($userId, $backend, false);
+ yield $user;
+ break;
+ }
+ }
+ }
+ } while (count($userIds) === $limit);
+ }
}
diff --git a/lib/public/IUserManager.php b/lib/public/IUserManager.php
index 50eaa9c98b7..3fd3234818e 100644
--- a/lib/public/IUserManager.php
+++ b/lib/public/IUserManager.php
@@ -231,4 +231,15 @@ interface IUserManager {
* @since 30.0.0
*/
public function getLastLoggedInUsers(?int $limit = null, int $offset = 0, string $search = ''): array;
+
+ /**
+ * Gets the list of users.
+ * An iterator is returned allowing the caller to stop the iteration at any time.
+ * The offset argument allows the caller to continue the iteration at a specific offset.
+ *
+ * @param int $offset from which offset to fetch
+ * @return \Iterator<IUser> list of IUser object
+ * @since 32.0.0
+ */
+ public function getSeenUsers(int $offset = 0): \Iterator;
}