Skip to content
Merged
Changes from all commits
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
feat(users): add disabled users to storage stats
And get the total number of users directly from IUserManager

Signed-off-by: Thomas Citharel <[email protected]>
  • Loading branch information
tcitworld authored and kesselb committed Jun 10, 2025
commit 744d70ad24da2fe797a11f0fa9d79b532c69c996
16 changes: 8 additions & 8 deletions lib/StorageStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@
use OCP\Files\IRootFolder;
use OCP\IAppConfig;
use OCP\IDBConnection;
use OCP\IUserManager;

class StorageStatistics {

public function __construct(
private IDBConnection $connection,
private IRootFolder $rootFolder,
private IAppConfig $appConfig,
private IUserManager $userManager,
) {
}

public function getStorageStatistics(): array {
return [
'num_users' => $this->countUserEntries(),
'num_disabled_users' => $this->countDisabledUserEntries(),
'num_files' => $this->getCountOf('filecache'),
'num_storages' => $this->getCountOf('storages'),
'num_storages_local' => $this->countStorages('local'),
Expand All @@ -40,14 +43,11 @@ public function getStorageStatistics(): array {
* count number of users
*/
protected function countUserEntries(): int {
$query = $this->connection->getQueryBuilder();
$query->selectAlias($query->createFunction('COUNT(*)'), 'num_entries')
->from('preferences')
->where($query->expr()->eq('configkey', $query->createNamedParameter('lastLogin')));
$result = $query->executeQuery();
$row = $result->fetch();
$result->closeCursor();
return (int)$row['num_entries'];
return $this->userManager->countSeenUsers();
}

protected function countDisabledUserEntries(): int {
return $this->userManager->countDisabledUsers();
}

protected function getCountOf(string $table): int {
Expand Down
Loading