diff options
| author | 2023-12-03 19:52:02 +0100 | |
|---|---|---|
| committer | 2023-12-03 19:52:02 +0100 | |
| commit | f0d4f2762d2b74eeadf2fb64ff83039b5cc16c26 (patch) | |
| tree | ebdb0bcffeb4370d1fa08defe7313dbf5f02e47a /app/Models/Feed.php | |
| parent | eb2c2d9a01ba54865b944f75d8436f933ed3ebfc (diff) | |
Rework keepmax (#5905)
* Rework keepmax
fix https://github.com/FreshRSS/FreshRSS/issues/5702
fix https://github.com/FreshRSS/FreshRSS/issues/5870
* More WIP
* Minor progress
* Progress
* Beta
* Improved debug message
* Revert noCommit
* Fix variable reset
* Remove debug syslogs
Diffstat (limited to 'app/Models/Feed.php')
| -rw-r--r-- | app/Models/Feed.php | 35 |
1 files changed, 19 insertions, 16 deletions
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; } /** |
