Skip to content

feat(services): add storage, cache, and DB services - #983

Open
karlitschek wants to merge 2 commits into
masterfrom
split/06-services-storage-db
Open

feat(services): add storage, cache, and DB services#983
karlitschek wants to merge 2 commits into
masterfrom
split/06-services-storage-db

Conversation

@karlitschek

Copy link
Copy Markdown
Member

Adds five read-only service classes used by the upcoming admin dashboard cards. None are wired into existing controllers yet, so this change is a pure addition with no behavior change.

  • DbHealth - largest tables on MySQL / PostgreSQL
  • CachingInfo - OPcache and APCu hit rates plus Redis config
  • ExternalStoragesInfo - mounts configured via files_external
  • DiskGrowth - rolling history snapshots with a
    days-until-full prediction
  • TopUsersByQuota - top users ranked by home::*/files size

Adds five read-only service classes used by the upcoming admin
dashboard cards. None are wired into existing controllers yet, so
this change is a pure addition with no behavior change.

* DbHealth             - largest tables on MySQL / PostgreSQL
* CachingInfo          - OPcache and APCu hit rates plus Redis config
* ExternalStoragesInfo - mounts configured via files_external
* DiskGrowth           - rolling history snapshots with a
                         days-until-full prediction
* TopUsersByQuota      - top users ranked by home::*/files size

Signed-off-by: Frank Karlitschek <frank@nextcloud.com>
Comment thread lib/DbHealth.php
Comment thread lib/DbHealth.php
Comment thread lib/DbHealth.php
Comment thread lib/DiskGrowth.php

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a set of new read-only “service” classes under OCA\ServerInfo intended to power upcoming admin dashboard cards, focused on DB health, caching status, external storage mounts, disk growth prediction, and identifying largest user home storages.

Changes:

  • Introduces new DB- and filesystem-backed service classes for collecting storage, caching, and database metrics.
  • Adds disk free-space history persistence + simple growth/prediction computation.
  • Adds queries for external mounts and top users by home storage size.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
lib/DbHealth.php New DB health service querying largest tables for MySQL/PostgreSQL.
lib/CachingInfo.php New cache status service for OPcache/APCu and Redis/memcache config.
lib/ExternalStoragesInfo.php New external storage mounts summary service (files_external).
lib/DiskGrowth.php New snapshot/history + disk growth estimation/prediction service.
lib/TopUsersByQuota.php New service to rank users by “home::” storage size via filecache.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/DiskGrowth.php
Comment on lines +16 to +18
* Persists daily snapshots of (free space + file count) and uses a
* simple linear regression over the last samples to predict when
* the system disk will fill up.
Comment thread lib/CachingInfo.php
Comment on lines +33 to +37
'memcache' => [
'local' => $this->shortClassName($this->config->getSystemValue('memcache.local', '')),
'distributed' => $this->shortClassName($this->config->getSystemValue('memcache.distributed', '')),
'locking' => $this->shortClassName($this->config->getSystemValue('memcache.locking', '')),
],
Comment thread lib/DiskGrowth.php
* simple linear regression over the last samples to predict when
* the system disk will fill up.
*
* Snapshots are stored in app config as JSON: list of {ts, free, files}.
Comment thread lib/DbHealth.php
Comment on lines +29 to +47
public function getDbHealth(): array {
$driver = (string)$this->config->getSystemValue('dbtype', 'sqlite');

try {
$tables = match ($driver) {
'mysql', 'mariadb' => $this->mysqlTables(),
'pgsql' => $this->pgTables(),
default => [],
};
} catch (\Throwable) {
$tables = [];
}

return [
'driver' => $driver,
'largestTables' => $tables,
'available' => $tables !== [] || $driver === 'sqlite',
];
}
Comment on lines +34 to +52
try {
$qb = $this->db->getQueryBuilder();
$qb->select('mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'type')
->from('external_mounts')
->setMaxResults(50);
$result = $qb->executeQuery();
$mounts = [];
while (($row = $result->fetch()) !== false) {
$mounts[] = [
'name' => $this->prettyMountPoint((string)($row['mount_point'] ?? '')),
'backend' => $this->shortBackend((string)($row['storage_backend'] ?? '')),
'scope' => (int)($row['type'] ?? 1) === 2 ? 'user' : 'admin',
];
}
$result->closeCursor();
return ['installed' => true, 'count' => count($mounts), 'mounts' => $mounts];
} catch (\Throwable) {
return ['installed' => true, 'count' => 0, 'mounts' => []];
}
Comment thread lib/DiskGrowth.php
* hasEnoughData: bool
* }
*/
public function getGrowthInfo(): array {
Comment thread lib/DbHealth.php
* available: bool
* }
*/
public function getDbHealth(): array {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants