diff options
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/README.md | 2 | ||||
| -rwxr-xr-x | cli/user-info.php | 50 |
2 files changed, 35 insertions, 17 deletions
diff --git a/cli/README.md b/cli/README.md index 47f28a7f7..b3ca09cb0 100644 --- a/cli/README.md +++ b/cli/README.md @@ -95,6 +95,8 @@ cd /usr/share/FreshRSS # -h, --human-readable display output in a human readable format # --header outputs some columns headers. # --json JSON format (disables --header and --human-readable but uses ISO Zulu format for dates). +# --no-db-size for faster responses by disabling database size calculation. +# --no-db-counts for faster responses by disabling counting the different types of articles in database. # --user indicates a username, and can be repeated. # Returns: 1) a * if the user is admin, 2) the name of the user, # 3) the date/time of last user action, 4) the size occupied, diff --git a/cli/user-info.php b/cli/user-info.php index 2771605ac..496d4bfdb 100755 --- a/cli/user-info.php +++ b/cli/user-info.php @@ -11,12 +11,18 @@ $cliOptions = new class extends CliOptionsParser { public bool $header; public bool $json; public bool $humanReadable; + /** Disable database size */ + public bool $noDbSize; + /** Disable database counts */ + public bool $noDbCounts; public function __construct() { $this->addOption('user', (new CliOption('user'))->typeOfArrayOfString()); $this->addOption('header', (new CliOption('header'))->withValueNone()); $this->addOption('json', (new CliOption('json'))->withValueNone()); $this->addOption('humanReadable', (new CliOption('human-readable', 'h'))->withValueNone()); + $this->addOption('noDbSize', (new CliOption('no-db-size'))->withValueNone()); + $this->addOption('noDbCounts', (new CliOption('no-db-counts'))->withValueNone()); parent::__construct(); } }; @@ -58,15 +64,23 @@ if ($cliOptions->header) { foreach ($users as $username) { $username = cliInitUser($username); - $catDAO = FreshRSS_Factory::createCategoryDao($username); - $feedDAO = FreshRSS_Factory::createFeedDao($username); - $entryDAO = FreshRSS_Factory::createEntryDao($username); - $tagDAO = FreshRSS_Factory::createTagDao($username); - $databaseDAO = FreshRSS_Factory::createDatabaseDAO($username); - - $nbEntries = $entryDAO->countUnreadRead(); - $nbFavorites = $entryDAO->countUnreadReadFavorites(); - $feedList = $feedDAO->listFeedsIds(); + if ($cliOptions->noDbCounts) { + $catDAO = null; + $feedDAO = null; + $tagDAO = null; + $nbEntries = null; + } else { + $catDAO = FreshRSS_Factory::createCategoryDao($username); + $feedDAO = FreshRSS_Factory::createFeedDao($username); + $entryDAO = FreshRSS_Factory::createEntryDao($username); + $tagDAO = FreshRSS_Factory::createTagDao($username); + $nbEntries = $entryDAO->countAsStates(); + } + if ($cliOptions->noDbSize) { + $databaseDAO = null; + } else { + $databaseDAO = FreshRSS_Factory::createDatabaseDAO($username); + } $data = [ 'default' => $username === FreshRSS_Context::systemConf()->default_user ? '*' : '', @@ -74,19 +88,21 @@ foreach ($users as $username) { 'admin' => FreshRSS_Context::userConf()->is_admin ? '*' : '', 'enabled' => FreshRSS_Context::userConf()->enabled ? '*' : '', 'last_user_activity' => FreshRSS_UserDAO::mtime($username), - 'database_size' => $databaseDAO->size(), - 'categories' => $catDAO->count(), - 'feeds' => count($feedList), - 'reads' => (int)$nbEntries['read'], - 'unreads' => (int)$nbEntries['unread'], - 'favourites' => (int)$nbFavorites['all'], - 'tags' => $tagDAO->count(), + 'database_size' => isset($databaseDAO) ? $databaseDAO->size() : '?', + 'categories' => isset($catDAO) ? $catDAO->count() : '?', + 'feeds' => isset($feedDAO) ? $feedDAO->count() : '?', + 'reads' => isset($nbEntries) ? $nbEntries['read'] : '?', + 'unreads' => isset($nbEntries) ? $nbEntries['unread'] : '?', + 'favourites' => isset($nbEntries) ? $nbEntries['favorites'] : '?', + 'tags' => isset($tagDAO) ? $tagDAO->count() : '?', 'lang' => FreshRSS_Context::userConf()->language, 'mail_login' => FreshRSS_Context::userConf()->mail_login, ]; if ($cliOptions->humanReadable) { //Human format $data['last_user_activity'] = date('c', $data['last_user_activity']); - $data['database_size'] = format_bytes($data['database_size']); + if (ctype_digit($data['database_size'])) { + $data['database_size'] = format_bytes($data['database_size']); + } } if ($cliOptions->json) { |
