mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-10-27 05:28:38 -04:00
Fix PostgreSQL and SQLite DB size estimation (#2562)
This commit is contained in:
1 parent
be4c942cb3
commit
3b65f2e586
3 files changed
+29
-7
No files matched your search
@@ -49,12 +49,23 @@ class FreshRSS_DatabaseDAOPGSQL extends FreshRSS_DatabaseDAOSQLite {
|
||||
);
|
||||
}
|
||||
|
||||
public function size($all = true) {
|
||||
$db = FreshRSS_Context::$system_conf->db;
|
||||
$sql = 'SELECT pg_size_pretty(pg_database_size(?))';
|
||||
$values = array($db['base']);
|
||||
$stm = $this->pdo->prepare($sql);
|
||||
$stm->execute($values);
|
||||
public function size($all = false) {
|
||||
if ($all) {
|
||||
$db = FreshRSS_Context::$system_conf->db;
|
||||
$sql = 'SELECT pg_database_size(:base)';
|
||||
$stm = $this->pdo->prepare($sql);
|
||||
$stm->bindParam(':base', $db['base']);
|
||||
$stm->execute();
|
||||
} else {
|
||||
$sql = "SELECT "
|
||||
. "pg_total_relation_size('{$this->pdo->prefix()}category') + "
|
||||
. "pg_total_relation_size('{$this->pdo->prefix()}feed') + "
|
||||
. "pg_total_relation_size('{$this->pdo->prefix()}entry') + "
|
||||
. "pg_total_relation_size('{$this->pdo->prefix()}entrytmp') + "
|
||||
. "pg_total_relation_size('{$this->pdo->prefix()}tag') + "
|
||||
. "pg_total_relation_size('{$this->pdo->prefix()}entrytag')";
|
||||
$stm = $this->pdo->query($sql);
|
||||
}
|
||||
$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
return $res[0];
|
||||
}
|
||||
|
||||
@@ -54,7 +54,15 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO {
|
||||
}
|
||||
|
||||
public function size($all = false) {
|
||||
return @filesize(join_path(DATA_PATH, 'users', $this->current_user, 'db.sqlite'));
|
||||
$sum = 0;
|
||||
if ($all) {
|
||||
foreach (glob(DATA_PATH . '/users/*/db.sqlite') as $filename) {
|
||||
$sum += @filesize($filename);
|
||||
}
|
||||
} else {
|
||||
$sum = @filesize(DATA_PATH . '/users/' . $this->current_user . '/db.sqlite');
|
||||
}
|
||||
return $sum;
|
||||
}
|
||||
|
||||
public function optimize() {
|
||||
|
||||
@@ -951,6 +951,9 @@ SQL;
|
||||
$sql .= ' WHERE f.priority > ' . intval($minPriority);
|
||||
}
|
||||
$stm = $this->pdo->query($sql);
|
||||
if ($stm == false) {
|
||||
return false;
|
||||
}
|
||||
$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
return isset($res[0]) ? $res[0] : 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user