aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Feed.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-06-16 16:11:16 +0200
committerGravatar GitHub <noreply@github.com> 2023-06-16 16:11:16 +0200
commit723f7577d0a388a90779930754c5aacb9f66b168 (patch)
treeaa863f67592d0795be83b533de981082e0713601 /app/Models/Feed.php
parent228d7adfdb90c3fdd179f80fbfde565eb06e0cec (diff)
Refactor lastSeen and markReadAsGone (#5470)
* Refactor lastSeen and markReadAsGone Make the logic a bit more robust and explicit * Remove forgotten SQL param * Add test inTransaction * More robust transaction * Add a debug log * Add max timestamp to markAsReadUponGone * Reduce number of debug lines * typing * Better detection of when feed is empty * More explicit case for push
Diffstat (limited to 'app/Models/Feed.php')
-rw-r--r--app/Models/Feed.php24
1 files changed, 18 insertions, 6 deletions
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 09f0ef068..a27259978 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -764,23 +764,35 @@ class FreshRSS_Feed extends Minz_Model {
/**
* Applies the *mark as read upon gone* policy, if enabled.
- * Remember to call updateCachedValue($id_feed) or updateCachedValues() just after.
+ * Remember to call `updateCachedValue($id_feed)` or `updateCachedValues()` just after.
* @return int|false the number of lines affected, or false if not applicable
*/
- public function markAsReadUponGone() {
+ public function markAsReadUponGone(bool $upstreamIsEmpty, int $maxTimestamp = 0) {
$readUponGone = $this->attributes('read_upon_gone');
if ($readUponGone === null) {
$readUponGone = FreshRSS_Context::$user_conf->mark_when['gone'];
}
- if ($readUponGone) {
+ if (!$readUponGone) {
+ return false;
+ }
+ if ($upstreamIsEmpty) {
+ if ($maxTimestamp <= 0) {
+ $maxTimestamp = time();
+ }
+ $entryDAO = FreshRSS_Factory::createEntryDao();
+ $affected = $entryDAO->markReadFeed($this->id(), $maxTimestamp . '000000');
+ } else {
$feedDAO = FreshRSS_Factory::createFeedDao();
- return $feedDAO->markAsReadUponGone($this->id());
+ $affected = $feedDAO->markAsReadUponGone($this->id());
}
- return false;
+ if ($affected > 0) {
+ Minz_Log::debug(__METHOD__ . " $affected items" . ($upstreamIsEmpty ? ' (all)' : '') . ' [' . $this->url(false) . ']');
+ }
+ return $affected;
}
/**
- * Remember to call updateCachedValue($id_feed) or updateCachedValues() just after
+ * Remember to call `updateCachedValue($id_feed)` or `updateCachedValues()` just after
* @return int|false
*/
public function cleanOldEntries() {