aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Controllers/feedController.php24
-rw-r--r--app/Controllers/javascriptController.php4
-rw-r--r--app/Models/EntryDAO.php24
-rwxr-xr-xapp/actualize_script.php1
-rwxr-xr-xcli/actualize-user.php6
5 files changed, 45 insertions, 14 deletions
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index 63c358da7..4ec4b5a55 100644
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -742,11 +742,12 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
}
/**
- * @param array<int,int> $newUnreadEntriesPerFeed
* @return int|false The number of articles marked as read, of false if error
*/
- private static function keepMaxUnreads(array $newUnreadEntriesPerFeed) {
+ private static function keepMaxUnreads() {
$affected = 0;
+ $entryDAO = FreshRSS_Factory::createEntryDao();
+ $newUnreadEntriesPerFeed = $entryDAO->newUnreadEntriesPerFeed();
$feedDAO = FreshRSS_Factory::createFeedDao();
$feeds = $feedDAO->listFeedsOrderUpdate(-1);
foreach ($feeds as $feed) {
@@ -801,26 +802,23 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
return $tagDAO->tagEntries($applyLabels);
}
- public static function commitNewEntries(): bool {
+ public static function commitNewEntries(): void {
$entryDAO = FreshRSS_Factory::createEntryDao();
- $newUnreadEntriesPerFeed = $entryDAO->newUnreadEntriesPerFeed();
- $nbNewEntries = array_sum($newUnreadEntriesPerFeed);
+ ['all' => $nbNewEntries, 'unread' => $nbNewUnreadEntries] = $entryDAO->countNewEntries();
if ($nbNewEntries > 0) {
if (!$entryDAO->inTransaction()) {
$entryDAO->beginTransaction();
}
if ($entryDAO->commitNewEntries()) {
- self::keepMaxUnreads($newUnreadEntriesPerFeed);
self::applyLabelActions($nbNewEntries);
+ if ($nbNewUnreadEntries > 0) {
+ self::keepMaxUnreads();
+ }
}
if ($entryDAO->inTransaction()) {
$entryDAO->commit();
}
}
-
- $databaseDAO = FreshRSS_Factory::createDatabaseDAO();
- $databaseDAO->minorDbMaintenance();
- return true;
}
/**
@@ -846,6 +844,12 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
self::commitNewEntries();
} else {
if ($id === 0 && $url === '') {
+ // Case of a batch refresh (e.g. cron)
+ $databaseDAO = FreshRSS_Factory::createDatabaseDAO();
+ $databaseDAO->minorDbMaintenance();
+ Minz_ExtensionManager::callHookVoid('freshrss_user_maintenance');
+
+ FreshRSS_feed_Controller::commitNewEntries();
FreshRSS_category_Controller::refreshDynamicOpmls();
}
[$updated_feeds, $feed, $nbNewArticles] = self::actualizeFeeds($id, $url, $maxFeeds);
diff --git a/app/Controllers/javascriptController.php b/app/Controllers/javascriptController.php
index 74e4a0dd9..f7ac5a852 100644
--- a/app/Controllers/javascriptController.php
+++ b/app/Controllers/javascriptController.php
@@ -20,6 +20,10 @@ class FreshRSS_javascript_Controller extends FreshRSS_ActionController {
header('Content-Type: application/json; charset=UTF-8');
Minz_Session::_param('actualize_feeds', false);
+ $databaseDAO = FreshRSS_Factory::createDatabaseDAO();
+ $databaseDAO->minorDbMaintenance();
+ Minz_ExtensionManager::callHookVoid('freshrss_user_maintenance');
+
$catDAO = FreshRSS_Factory::createCategoryDao();
$this->view->categories = $catDAO->listCategoriesOrderUpdate(FreshRSS_Context::userConf()->dynamic_opml_ttl_default);
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index f770ce400..bb0b9af43 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -274,7 +274,29 @@ SQL;
}
/**
- * Count the number of new entries in the temporary table (which have not yet been committed), grouped by feed ID.
+ * Count the number of new entries in the temporary table (which have not yet been committed), grouped by read / unread.
+ * @return array{'all':int,'unread':int,'read':int}
+ */
+ public function countNewEntries(): array {
+ $sql = <<<'SQL'
+ SELECT is_read, COUNT(id) AS nb_entries FROM `_entrytmp`
+ GROUP BY is_read
+ SQL;
+ $lines = $this->fetchAssoc($sql) ?? [];
+ $nbRead = 0;
+ $nbUnread = 0;
+ foreach ($lines as $line) {
+ if (empty($line['is_read'])) {
+ $nbUnread = (int)($line['nb_entries'] ?? 0);
+ } else {
+ $nbRead = (int)($line['nb_entries'] ?? 0);
+ }
+ }
+ return ['all' => $nbRead + $nbUnread, 'unread' => $nbUnread, 'read' => $nbRead];
+ }
+
+ /**
+ * Count the number of new unread entries in the temporary table (which have not yet been committed), grouped by feed ID.
* @return array<int,int>
*/
public function newUnreadEntriesPerFeed(): array {
diff --git a/app/actualize_script.php b/app/actualize_script.php
index df3327e10..e55c1e080 100755
--- a/app/actualize_script.php
+++ b/app/actualize_script.php
@@ -103,7 +103,6 @@ foreach ($users as $user) {
notice('FreshRSS actualize ' . $user . '…');
echo $user, ' '; //Buffered
- Minz_ExtensionManager::callHookVoid('freshrss_user_maintenance');
$app->run();
if (!invalidateHttpCache()) {
diff --git a/cli/actualize-user.php b/cli/actualize-user.php
index f2fae116c..03af5f5c8 100755
--- a/cli/actualize-user.php
+++ b/cli/actualize-user.php
@@ -20,11 +20,13 @@ if (!empty($options['invalid']) || empty($options['valid']['user']) || !is_strin
}
$username = cliInitUser($options['valid']['user']);
+fwrite(STDERR, 'FreshRSS actualizing user “' . $username . "”…\n");
+$databaseDAO = FreshRSS_Factory::createDatabaseDAO();
+$databaseDAO->minorDbMaintenance();
Minz_ExtensionManager::callHookVoid('freshrss_user_maintenance');
-fwrite(STDERR, 'FreshRSS actualizing user “' . $username . "”…\n");
-
+FreshRSS_feed_Controller::commitNewEntries();
$result = FreshRSS_category_Controller::refreshDynamicOpmls();
if (!empty($result['errors'])) {
$errors = $result['errors'];