mirror of
https://github.com/nextcloud/server.git
synced 2026-06-13 18:50:47 -04:00
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>
This commit is contained in:
parent
b98b888346
commit
97d1295ff2
2 changed files with 37 additions and 0 deletions
|
|
@ -819,4 +819,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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -221,4 +221,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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue