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>
pull/51808/head
Louis Chemineau 2025-03-26 21:03:53 +07:00 committed by backportbot[bot]
parent a198345867
commit cd3d955e21
2 changed files with 37 additions and 0 deletions

@ -851,4 +851,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);
}
}

@ -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;
}