diff --git a/lib/Jobs/UpdateStorageStats.php b/lib/Jobs/UpdateStorageStats.php index 6bbc5b57..9f5d2545 100644 --- a/lib/Jobs/UpdateStorageStats.php +++ b/lib/Jobs/UpdateStorageStats.php @@ -12,13 +12,13 @@ use OCA\ServerInfo\StorageStatistics; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; -use OCP\IConfig; +use OCP\IAppConfig; class UpdateStorageStats extends TimedJob { private StorageStatistics $storageStatistics; - public function __construct(ITimeFactory $time, StorageStatistics $storageStatistics, IConfig $config) { - $this->setInterval((int)$config->getAppValue('serverinfo', 'job_interval_storage_stats', (string)(60 * 60 * 3))); + public function __construct(ITimeFactory $time, StorageStatistics $storageStatistics, IAppConfig $appConfig) { + $this->setInterval($appConfig->getValueInt('serverinfo', 'job_interval_storage_stats', 60 * 60 * 3)); parent::__construct($time); $this->storageStatistics = $storageStatistics; diff --git a/lib/StorageStatistics.php b/lib/StorageStatistics.php index 81d37fce..b53b66d9 100644 --- a/lib/StorageStatistics.php +++ b/lib/StorageStatistics.php @@ -10,16 +10,17 @@ namespace OCA\ServerInfo; -use OCP\IConfig; +use OCP\Files\IRootFolder; +use OCP\IAppConfig; use OCP\IDBConnection; class StorageStatistics { - private IDBConnection $connection; - private IConfig $config; - public function __construct(IDBConnection $connection, IConfig $config) { - $this->connection = $connection; - $this->config = $config; + public function __construct( + private IDBConnection $connection, + private IRootFolder $rootFolder, + private IAppConfig $appConfig, + ) { } public function getStorageStatistics(): array { @@ -30,6 +31,8 @@ public function getStorageStatistics(): array { 'num_storages_local' => $this->countStorages('local'), 'num_storages_home' => $this->countStorages('home'), 'num_storages_other' => $this->countStorages('other'), + 'size_appdata_storage' => $this->appConfig->getValueFloat('serverinfo', 'size_appdata_storage'), + 'num_files_appdata' => $this->getCountOf('appdata_files'), ]; } @@ -48,7 +51,7 @@ protected function countUserEntries(): int { } protected function getCountOf(string $table): int { - return (int)$this->config->getAppValue('serverinfo', 'cached_count_' . $table, '0'); + return $this->appConfig->getValueInt('serverinfo', 'cached_count_' . $table); } public function updateStorageCounts(): void { @@ -73,8 +76,10 @@ public function updateStorageCounts(): void { } $storageResult->closeCursor(); - $this->config->setAppValue('serverinfo', 'cached_count_filecache', (string)$fileCount); - $this->config->setAppValue('serverinfo', 'cached_count_storages', (string)$storageCount); + $this->updateAppDataStorageStats(); + + $this->appConfig->setValueInt('serverinfo', 'cached_count_filecache', $fileCount); + $this->appConfig->setValueInt('serverinfo', 'cached_count_storages', $storageCount); } protected function countStorages(string $type): int { @@ -94,4 +99,19 @@ protected function countStorages(string $type): int { $result->closeCursor(); return (int)$row['num_entries']; } + + public function updateAppDataStorageStats(): void { + $appDataPath = $this->rootFolder->getAppDataDirectoryName(); + $appDataFolder = $this->rootFolder->get($appDataPath); + $this->appConfig->setValueFloat('serverinfo', 'size_appdata_storage', $appDataFolder->getSize()); + + $query = $this->connection->getQueryBuilder(); + $query->select($query->func()->count()) + ->from('filecache') + ->where($query->expr()->like('path', $query->createNamedParameter($appDataPath . '%'))); + $fileResult = $query->executeQuery(); + $fileCount = (int)$fileResult->fetchOne(); + $fileResult->closeCursor(); + $this->appConfig->setValueInt('serverinfo', 'cached_count_appdata_files', $fileCount); + } }