Skip to content
Closed
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: Support limit argument in getSeenUsers
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed May 21, 2025
commit ea0f589c327ef0cbf2e114265fcd5898a203605a
26 changes: 13 additions & 13 deletions lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ public function callForSeenUsers(\Closure $callback) {
}

/**
* 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.
*
Expand Down Expand Up @@ -755,19 +755,19 @@ 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;
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) {
Expand All @@ -778,6 +778,6 @@ public function getSeenUsers(int $offset = 0): \Iterator {
}
}
}
} while (count($userIds) === $limit);
} while (count($userIds) === $batchSize && $limit !== 0);
}
}
4 changes: 3 additions & 1 deletion lib/public/IUserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ public function validateUserId(string $uid, bool $checkDataDirectory = false): v
* 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 29.0.15
* @since 29.0.16 Added the $limit argument
*/
public function getSeenUsers(int $offset = 0): \Iterator;
public function getSeenUsers(int $offset = 0, ?int $limit = null): \Iterator;
}