aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/EntryDAO.php20
-rw-r--r--app/Models/Feed.php35
-rw-r--r--app/Models/FeedDAO.php8
-rw-r--r--app/Models/UserConfiguration.php2
4 files changed, 44 insertions, 21 deletions
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 403f4e493..23ac3c918 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -274,6 +274,26 @@ SQL;
}
/**
+ * Count the number of new entries in the temporary table (which have not yet been committed), grouped by feed ID.
+ * @return array<int,int>
+ */
+ public function newUnreadEntriesPerFeed(): array {
+ $sql = <<<'SQL'
+ SELECT id_feed, COUNT(id) AS nb_entries FROM `_entrytmp`
+ WHERE is_read = 0
+ GROUP BY id_feed
+ SQL;
+ $lines = $this->fetchAssoc($sql) ?? [];
+ $result = [];
+ foreach ($lines as $line) {
+ if (!empty($line['id_feed'])) {
+ $result[(int)$line['id_feed']] = (int)($line['nb_entries'] ?? 0);
+ }
+ }
+ return $result;
+ }
+
+ /**
* Toggle favorite marker on one or more article
*
* @todo simplify the query by removing the str_repeat. I am pretty sure
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index d94763e6e..afd10909e 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -46,7 +46,6 @@ class FreshRSS_Feed extends Minz_Model {
private ?FreshRSS_Category $category;
private int $nbEntries = -1;
private int $nbNotRead = -1;
- private int $nbPendingNotRead = 0;
private string $name = '';
private string $website = '';
private string $description = '';
@@ -211,13 +210,13 @@ class FreshRSS_Feed extends Minz_Model {
return $this->nbEntries;
}
- public function nbNotRead(bool $includePending = false): int {
+ public function nbNotRead(): int {
if ($this->nbNotRead < 0) {
$feedDAO = FreshRSS_Factory::createFeedDao();
$this->nbNotRead = $feedDAO->countNotRead($this->id());
}
- return $this->nbNotRead + ($includePending ? $this->nbPendingNotRead : 0);
+ return $this->nbNotRead;
}
public function faviconPrepare(): void {
@@ -750,15 +749,7 @@ class FreshRSS_Feed extends Minz_Model {
}
/**
- * To keep track of some new potentially unread articles since last commit+fetch from database
- */
- public function incPendingUnread(int $n = 1): void {
- $this->nbPendingNotRead += $n;
- }
-
- /**
- * Remember to call updateCachedValue($id_feed) or updateCachedValues() just after.
- * @return int|false the number of lines affected, or false if not applicable
+ * @return int|null The max number of unread articles to keep, or null if disabled.
* @throws JsonException
*/
public function keepMaxUnread() {
@@ -766,11 +757,23 @@ class FreshRSS_Feed extends Minz_Model {
if ($keepMaxUnread === null) {
$keepMaxUnread = FreshRSS_Context::$user_conf->mark_when['max_n_unread'];
}
- $keepMaxUnread = (int)$keepMaxUnread;
- if ($keepMaxUnread > 0 && $this->nbNotRead(false) + $this->nbPendingNotRead > $keepMaxUnread) {
- return FreshRSS_Factory::createFeedDao()->keepMaxUnread($this->id(), max(0, $keepMaxUnread - $this->nbPendingNotRead));
+ return is_int($keepMaxUnread) && $keepMaxUnread >= 0 ? $keepMaxUnread : null;
+ }
+
+ /**
+ * @return int|false The number of articles marked as read, of false if error
+ */
+ public function markAsReadMaxUnread() {
+ $keepMaxUnread = $this->keepMaxUnread();
+ if ($keepMaxUnread === null) {
+ return false;
}
- return false;
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ $affected = $feedDAO->markAsReadMaxUnread($this->id(), $keepMaxUnread);
+ if ($affected > 0) {
+ Minz_Log::debug(__METHOD__ . " $affected items [" . $this->url(false) . ']');
+ }
+ return $affected;
}
/**
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index 82e33dd84..055ec60e4 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -373,7 +373,7 @@ SQL;
* @return array<FreshRSS_Feed>
*/
public function listFeedsOrderUpdate(int $defaultCacheDuration = 3600, int $limit = 0): array {
- $sql = 'SELECT id, url, kind, name, website, `lastUpdate`, `pathEntries`, `httpAuth`, ttl, attributes '
+ $sql = 'SELECT id, url, kind, name, website, `lastUpdate`, `pathEntries`, `httpAuth`, ttl, attributes, `cache_nbEntries`, `cache_nbUnreads` '
. 'FROM `_feed` '
. ($defaultCacheDuration < 0 ? '' : 'WHERE ttl >= ' . FreshRSS_Feed::TTL_DEFAULT
. ' AND `lastUpdate` < (' . (time() + 60)
@@ -468,7 +468,7 @@ SQL;
* Remember to call updateCachedValues() after calling this function
* @return int|false number of lines affected or false in case of error
*/
- public function keepMaxUnread(int $id, int $n) {
+ public function markAsReadMaxUnread(int $id, int $n) {
//Double SELECT for MySQL workaround ERROR 1093 (HY000)
$sql = <<<'SQL'
UPDATE `_entry` SET is_read=1
@@ -610,8 +610,8 @@ SQL;
$myFeed->_error($dao['error'] ?? 0);
$myFeed->_ttl($dao['ttl'] ?? FreshRSS_Feed::TTL_DEFAULT);
$myFeed->_attributes('', $dao['attributes'] ?? '');
- $myFeed->_nbNotRead($dao['cache_nbUnreads'] ?? 0);
- $myFeed->_nbEntries($dao['cache_nbEntries'] ?? 0);
+ $myFeed->_nbNotRead($dao['cache_nbUnreads'] ?? -1);
+ $myFeed->_nbEntries($dao['cache_nbEntries'] ?? -1);
if (isset($dao['id'])) {
$myFeed->_id($dao['id']);
}
diff --git a/app/Models/UserConfiguration.php b/app/Models/UserConfiguration.php
index 05e36aae6..b51c2b632 100644
--- a/app/Models/UserConfiguration.php
+++ b/app/Models/UserConfiguration.php
@@ -34,7 +34,7 @@ declare(strict_types=1);
* @property bool $lazyload
* @property string $mail_login
* @property bool $mark_updated_article_unread
- * @property array<string,bool> $mark_when
+ * @property array<string,bool|int> $mark_when
* @property int $max_posts_per_rss
* @property-read array<string,int> $limits
* @property int|null $old_entries