diff --git a/lib/Db/UserMapper.php b/lib/Db/UserMapper.php index ace1651c..2f91604c 100644 --- a/lib/Db/UserMapper.php +++ b/lib/Db/UserMapper.php @@ -169,4 +169,22 @@ public function getOrCreate(int $providerId, string $sub, bool $id4me = false): $user->setUserId($userId); return $this->insert($user); } + + /** + * Count the total number of users provisioned by the OIDC backend. + * + * @return int the number of rows in the user_oidc table + */ + public function countUsers(): int { + $qb = $this->db->getQueryBuilder(); + + $qb->selectAlias($qb->func()->count('*'), 'user_count') + ->from($this->getTableName()); + + $result = $qb->executeQuery(); + $count = $result->fetchOne(); + $result->closeCursor(); + + return (int)$count; + } } diff --git a/lib/User/Backend.php b/lib/User/Backend.php index 538276ef..a25aadd7 100644 --- a/lib/User/Backend.php +++ b/lib/User/Backend.php @@ -76,9 +76,13 @@ public function getBackendName(): string { return Application::APP_ID; } + /** + * Count the number of users managed by this OIDC backend. + * + * @return int the number of provisioned OIDC users + */ public function countUsers(): int { - $uids = $this->getUsers(); - return count($uids); + return $this->userMapper->countUsers(); } public function deleteUser($uid): bool {