Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storage): add size of appdata folder to statistics #728

Merged
merged 3 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions lib/Jobs/UpdateStorageStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 18 additions & 9 deletions lib/StorageStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -30,6 +31,7 @@ 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'),
];
}

Expand All @@ -48,7 +50,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 {
Expand All @@ -73,8 +75,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->updateAppDataStorageSize();

$this->appConfig->setValueInt('serverinfo', 'cached_count_filecache', $fileCount);
$this->appConfig->setValueInt('serverinfo', 'cached_count_storages', $storageCount);
}

protected function countStorages(string $type): int {
Expand All @@ -94,4 +98,9 @@ protected function countStorages(string $type): int {
$result->closeCursor();
return (int)$row['num_entries'];
}

public function updateAppDataStorageSize(): void {
$appDataFolder = $this->rootFolder->get($this->rootFolder->getAppDataDirectoryName());
$this->appConfig->setValueFloat('serverinfo', 'size_appdata_storage', $appDataFolder->getSize());
}
}
Loading