Skip to content

Commit 1fe7f80

Browse files
artongebackportbot[bot]
authored andcommitted
feat: Support limit argument in getSeenUsers
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent b91585c commit 1fe7f80

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lib/private/User/Manager.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ public function callForSeenUsers(\Closure $callback) {
650650
}
651651

652652
/**
653-
* Getting all userIds that have a listLogin value requires checking the
653+
* Getting all userIds that have a lastLogin value requires checking the
654654
* value in php because on oracle you cannot use a clob in a where clause,
655655
* preventing us from doing a not null or length(value) > 0 check.
656656
*
@@ -828,19 +828,19 @@ public function getDisplayNameCache(): DisplayNameCache {
828828
return $this->displayNameCache;
829829
}
830830

831-
/**
832-
* Gets the list of users sorted by lastLogin, from most recent to least recent
833-
*
834-
* @param int $offset from which offset to fetch
835-
* @return \Iterator<IUser> list of user IDs
836-
* @since 30.0.0
837-
*/
838-
public function getSeenUsers(int $offset = 0): \Iterator {
839-
$limit = 1000;
831+
public function getSeenUsers(int $offset = 0, ?int $limit = null): \Iterator {
832+
$maxBatchSize = 1000;
840833

841834
do {
842-
$userIds = $this->getSeenUserIds($limit, $offset);
843-
$offset += $limit;
835+
if ($limit !== null) {
836+
$batchSize = min($limit, $maxBatchSize);
837+
$limit -= $batchSize;
838+
} else {
839+
$batchSize = $maxBatchSize;
840+
}
841+
842+
$userIds = $this->getSeenUserIds($batchSize, $offset);
843+
$offset += $batchSize;
844844

845845
foreach ($userIds as $userId) {
846846
foreach ($this->backends as $backend) {
@@ -851,6 +851,6 @@ public function getSeenUsers(int $offset = 0): \Iterator {
851851
}
852852
}
853853
}
854-
} while (count($userIds) === $limit);
854+
} while (count($userIds) === $batchSize && $limit !== 0);
855855
}
856856
}

lib/public/IUserManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,9 @@ public function getLastLoggedInUsers(?int $limit = null, int $offset = 0, string
238238
* The offset argument allows the caller to continue the iteration at a specific offset.
239239
*
240240
* @param int $offset from which offset to fetch
241+
* @param int|null $limit maximum number of records to fetch
241242
* @return \Iterator<IUser> list of IUser object
242243
* @since 32.0.0
243244
*/
244-
public function getSeenUsers(int $offset = 0): \Iterator;
245+
public function getSeenUsers(int $offset = 0, ?int $limit = null): \Iterator;
245246
}

0 commit comments

Comments
 (0)