mirror of
https://github.com/nextcloud/server.git
synced 2026-04-20 22:00:39 -04:00
feat: Support limit argument in getSeenUsers
Signed-off-by: Louis Chemineau <louis@chmn.me>
This commit is contained in:
parent
2908f7602a
commit
1d91e40fe8
2 changed files with 15 additions and 14 deletions
|
|
@ -634,7 +634,7 @@ class Manager extends PublicEmitter implements IUserManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Getting all userIds that have a listLogin value requires checking the
|
||||
* Getting all userIds that have a lastLogin value requires checking the
|
||||
* value in php because on oracle you cannot use a clob in a where clause,
|
||||
* preventing us from doing a not null or length(value) > 0 check.
|
||||
*
|
||||
|
|
@ -813,19 +813,19 @@ class Manager extends PublicEmitter implements IUserManager {
|
|||
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;
|
||||
public function getSeenUsers(int $offset = 0, ?int $limit = null): \Iterator {
|
||||
$maxBatchSize = 1000;
|
||||
|
||||
do {
|
||||
$userIds = $this->getSeenUserIds($limit, $offset);
|
||||
$offset += $limit;
|
||||
if ($limit !== null) {
|
||||
$batchSize = min($limit, $maxBatchSize);
|
||||
$limit -= $batchSize;
|
||||
} else {
|
||||
$batchSize = $maxBatchSize;
|
||||
}
|
||||
|
||||
$userIds = $this->getSeenUserIds($batchSize, $offset);
|
||||
$offset += $batchSize;
|
||||
|
||||
foreach ($userIds as $userId) {
|
||||
foreach ($this->backends as $backend) {
|
||||
|
|
@ -836,6 +836,6 @@ class Manager extends PublicEmitter implements IUserManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
} while (count($userIds) === $limit);
|
||||
} while (count($userIds) === $batchSize && $limit !== 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -239,8 +239,9 @@ interface IUserManager {
|
|||
* The offset argument allows the caller to continue the iteration at a specific offset.
|
||||
*
|
||||
* @param int $offset from which offset to fetch
|
||||
* @param int|null $limit maximum number of records to fetch
|
||||
* @return \Iterator<IUser> list of IUser object
|
||||
* @since 32.0.0
|
||||
*/
|
||||
public function getSeenUsers(int $offset = 0): \Iterator;
|
||||
public function getSeenUsers(int $offset = 0, ?int $limit = null): \Iterator;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue