aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2017-10-12 20:11:06 +0200
committerGravatar GitHub <noreply@github.com> 2017-10-12 20:11:06 +0200
commitf632a346269100d6a93bef318ffa66c97f16f6fa (patch)
treeaffdcac8889fcaeb04c9934a37ae6f3a5422c0ea /cli
parent6372e51cd6a6846c11366b5b5f56409198af6e24 (diff)
CLI optimize database (#1663)
CLI optimize database https://github.com/FreshRSS/FreshRSS/issues/1583 And VACUUM in SQLite https://github.com/FreshRSS/FreshRSS/issues/918 Add VACUUM for PostgreSQL (Not tested yet)
Diffstat (limited to 'cli')
-rw-r--r--cli/README.md3
-rwxr-xr-xcli/db-optimize.php20
-rwxr-xr-xcli/user-info.php5
3 files changed, 26 insertions, 2 deletions
diff --git a/cli/README.md b/cli/README.md
index ce1be10a7..6f907566c 100644
--- a/cli/README.md
+++ b/cli/README.md
@@ -69,6 +69,9 @@ cd /usr/share/FreshRSS
# Returns: 1) a * iff the user is admin, 2) the name of the user,
# 3) the date/time of last user action, 4) the size occupied,
# and the number of: 5) categories, 6) feeds, 7) read articles, 8) unread articles, and 9) favourites
+
+./cli/db-optimize.php --user username
+# Optimize database (reduces the size) for a given user (perform `OPTIMIZE TABLE` in MySQL, `VACUUM` in SQLite)
```
diff --git a/cli/db-optimize.php b/cli/db-optimize.php
new file mode 100755
index 000000000..83123a669
--- /dev/null
+++ b/cli/db-optimize.php
@@ -0,0 +1,20 @@
+#!/usr/bin/php
+<?php
+require('_cli.php');
+
+$options = getopt('', array(
+ 'user:',
+ ));
+
+if (empty($options['user'])) {
+ fail('Usage: ' . basename(__FILE__) . " --user username");
+}
+
+$username = cliInitUser($options['user']);
+
+echo 'FreshRSS optimizing database for user “', $username, "”…\n";
+
+$databaseDAO = FreshRSS_Factory::createDatabaseDAO($username);
+$ok = $databaseDAO->optimize();
+
+done($ok);
diff --git a/cli/user-info.php b/cli/user-info.php
index aa3e239b8..41b95cbf3 100755
--- a/cli/user-info.php
+++ b/cli/user-info.php
@@ -19,6 +19,7 @@ foreach ($users as $username) {
$catDAO = new FreshRSS_CategoryDAO();
$feedDAO = FreshRSS_Factory::createFeedDao($username);
$entryDAO = FreshRSS_Factory::createEntryDao($username);
+ $databaseDAO = FreshRSS_Factory::createDatabaseDAO($username);
$nbEntries = $entryDAO->countUnreadRead();
$nbFavorites = $entryDAO->countUnreadReadFavorites();
@@ -27,7 +28,7 @@ foreach ($users as $username) {
echo
$username, "\t",
date('c', FreshRSS_UserDAO::mtime($username)), "\t",
- format_bytes($entryDAO->size()), "\t",
+ format_bytes($databaseDAO->size()), "\t",
$catDAO->count(), " categories\t",
count($feedDAO->listFeedsIds()), " feeds\t",
$nbEntries['read'], " reads\t",
@@ -38,7 +39,7 @@ foreach ($users as $username) {
echo
$username, "\t",
FreshRSS_UserDAO::mtime($username), "\t",
- $entryDAO->size(), "\t",
+ $databaseDAO->size(), "\t",
$catDAO->count(), "\t",
count($feedDAO->listFeedsIds()), "\t",
$nbEntries['read'], "\t",