Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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 <[email protected]>
  • Loading branch information
artonge committed Mar 31, 2025
commit 0aa31997ed3b1638e6b4faa5ebb2989f2b563d70
26 changes: 26 additions & 0 deletions lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,4 +794,30 @@ private function verifyUid(string $uid, bool $checkDataDirectory = false): bool
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);
}
}
11 changes: 11 additions & 0 deletions lib/public/IUserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,15 @@ public function getByEmail($email);
* @since 26.0.0
*/
public function validateUserId(string $uid, bool $checkDataDirectory = false): void;

/**
* 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 29.0.15
*/
public function getSeenUsers(int $offset = 0): \Iterator;
}