From 610c6a4c76f45ac92c0f12c7438ec437d0948951 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Thu, 26 Mar 2026 23:01:00 +0100 Subject: [PATCH 1/2] refactor: Use modern way to obtain pgsql size Signed-off-by: Daniel Kesselberg AI-assisted: Claude Code (Claude Sonnet 4.6) --- lib/DatabaseStatistics.php | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/lib/DatabaseStatistics.php b/lib/DatabaseStatistics.php index 3a8b896f..10408406 100644 --- a/lib/DatabaseStatistics.php +++ b/lib/DatabaseStatistics.php @@ -97,30 +97,11 @@ protected function databaseSize(): string { } break; case 'pgsql': - $sql = "SELECT proname - FROM pg_proc - WHERE proname = 'pg_database_size'"; - $result = $this->connection->executeQuery($sql); - $row = $result->fetch(); + $database = $this->config->getSystemValueString('dbname'); + $sql = 'SELECT pg_database_size(:dbname) as size'; + $result = $this->connection->executeQuery($sql, ['dbname' => $database]); + $database_size = $result->fetchOne(); $result->closeCursor(); - if ($row['proname'] === 'pg_database_size') { - $database = $this->config->getSystemValue('dbname'); - if (strpos($database, '.') !== false) { - [$database, ] = explode('.', $database); - } - $sql = "SELECT oid - FROM pg_database - WHERE datname = '$database'"; - $result = $this->connection->executeQuery($sql); - $row = $result->fetch(); - $result->closeCursor(); - $oid = $row['oid']; - $sql = 'SELECT pg_database_size(' . $oid . ') as size'; - $result = $this->connection->executeQuery($sql); - $row = $result->fetch(); - $result->closeCursor(); - $database_size = $row['size']; - } break; case 'oci': $sql = 'SELECT SUM(bytes) as dbsize From 99cd1b7c91a20e5555dcc1794e62516e9dfbfbe4 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Thu, 26 Mar 2026 23:09:58 +0100 Subject: [PATCH 2/2] refactor: Replace fetch with fetchOne Signed-off-by: Daniel Kesselberg --- lib/ShareStatistics.php | 18 +++++++++++++----- lib/StorageStatistics.php | 9 +++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/ShareStatistics.php b/lib/ShareStatistics.php index 6ec599e6..423bba81 100644 --- a/lib/ShareStatistics.php +++ b/lib/ShareStatistics.php @@ -59,10 +59,14 @@ protected function countEntries(string $tableName): int { $query->select($query->func()->count('*', 'num_entries')) ->from($tableName); $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchOne(); $result->closeCursor(); - return (int)$row['num_entries']; + if ($row === false) { + return 0; + } + + return (int)$row; } /** @@ -72,7 +76,7 @@ protected function countEntries(string $tableName): int { */ protected function countShares(int $type, bool $noPassword = false): int { $query = $this->connection->getQueryBuilder(); - $query->selectAlias($query->createFunction('COUNT(*)'), 'num_entries') + $query->select($query->func()->count('*', 'num_entries')) ->from('share') ->where($query->expr()->eq('share_type', $query->createNamedParameter($type))); @@ -81,9 +85,13 @@ protected function countShares(int $type, bool $noPassword = false): int { } $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchOne(); $result->closeCursor(); - return (int)$row['num_entries']; + if ($row === false) { + return 0; + } + + return (int)$row; } } diff --git a/lib/StorageStatistics.php b/lib/StorageStatistics.php index 0e14a759..5f17743d 100644 --- a/lib/StorageStatistics.php +++ b/lib/StorageStatistics.php @@ -95,9 +95,14 @@ protected function countStorages(string $type): int { $query->andWhere($query->expr()->notLike('id', $query->createNamedParameter('local::%'))); } $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchOne(); $result->closeCursor(); - return (int)$row['num_entries']; + + if ($row === false) { + return 0; + } + + return (int)$row; } public function updateAppDataStorageStats(): void {