Skip to content

Commit 0313ab3

Browse files
committed
feat: Support limit argument in getSeenUsers
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent f42a0ed commit 0313ab3

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
@@ -607,7 +607,7 @@ public function callForSeenUsers(\Closure $callback) {
607607
}
608608

609609
/**
610-
* Getting all userIds that have a listLogin value requires checking the
610+
* Getting all userIds that have a lastLogin value requires checking the
611611
* value in php because on oracle you cannot use a clob in a where clause,
612612
* preventing us from doing a not null or length(value) > 0 check.
613613
*
@@ -780,19 +780,19 @@ public function getDisplayNameCache(): DisplayNameCache {
780780
return $this->displayNameCache;
781781
}
782782

783-
/**
784-
* Gets the list of users sorted by lastLogin, from most recent to least recent
785-
*
786-
* @param int $offset from which offset to fetch
787-
* @return \Iterator<IUser> list of user IDs
788-
* @since 30.0.0
789-
*/
790-
public function getSeenUsers(int $offset = 0): \Iterator {
791-
$limit = 1000;
783+
public function getSeenUsers(int $offset = 0, ?int $limit = null): \Iterator {
784+
$maxBatchSize = 1000;
792785

793786
do {
794-
$userIds = $this->getSeenUserIds($limit, $offset);
795-
$offset += $limit;
787+
if ($limit !== null) {
788+
$batchSize = min($limit, $maxBatchSize);
789+
$limit -= $batchSize;
790+
} else {
791+
$batchSize = $maxBatchSize;
792+
}
793+
794+
$userIds = $this->getSeenUserIds($batchSize, $offset);
795+
$offset += $batchSize;
796796

797797
foreach ($userIds as $userId) {
798798
foreach ($this->backends as $backend) {
@@ -803,6 +803,6 @@ public function getSeenUsers(int $offset = 0): \Iterator {
803803
}
804804
}
805805
}
806-
} while (count($userIds) === $limit);
806+
} while (count($userIds) === $batchSize && $limit !== 0);
807807
}
808808
}

lib/public/IUserManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,9 @@ public function getLastLoggedInUsers(?int $limit = null, int $offset = 0, string
228228
* The offset argument allows the caller to continue the iteration at a specific offset.
229229
*
230230
* @param int $offset from which offset to fetch
231+
* @param int|null $limit maximum number of records to fetch
231232
* @return \Iterator<IUser> list of IUser object
232233
* @since 32.0.0
233234
*/
234-
public function getSeenUsers(int $offset = 0): \Iterator;
235+
public function getSeenUsers(int $offset = 0, ?int $limit = null): \Iterator;
235236
}

0 commit comments

Comments
 (0)