Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: use IAppConfig for storage statistics caching
Signed-off-by: Thomas Citharel <[email protected]>
  • Loading branch information
tcitworld committed Jan 7, 2025
commit a45296447545ebfc761f623681712a7e5b62fab7
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
14 changes: 4 additions & 10 deletions lib/StorageStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,15 @@

use OCP\Files\IRootFolder;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDBConnection;

class StorageStatistics {
private IDBConnection $connection;
private IConfig $config;

public function __construct(
IDBConnection $connection,
IConfig $config,
private IDBConnection $connection,
private IRootFolder $rootFolder,
private IAppConfig $appConfig,
) {
$this->connection = $connection;
$this->config = $config;
}

public function getStorageStatistics(): array {
Expand Down Expand Up @@ -56,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 @@ -83,8 +77,8 @@ public function updateStorageCounts(): void {

$this->updateAppDataStorageSize();

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

protected function countStorages(string $type): int {
Expand Down
Loading