aboutsummaryrefslogtreecommitdiff
path: root/app/Models/EntryDAO.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-05-09 22:31:43 +0200
committerGravatar GitHub <noreply@github.com> 2023-05-09 22:31:43 +0200
commit4c5f3bbd9b81e73316c794bd47debf1659e7723c (patch)
tree6c7e11c657fb55ee2a751a066c9bae21f5a5d407 /app/Models/EntryDAO.php
parent26bc0e0ee9a23631b808e7328252cfb7865b9941 (diff)
Fix markAsReadUponGone (#5382)
Fix regression from https://github.com/FreshRSS/FreshRSS/pull/5315 which indroduced a bug for cached feeds. We now update the `lastSeen` property of entries to account for the fact that they are unchanged but still existing.
Diffstat (limited to 'app/Models/EntryDAO.php')
-rw-r--r--app/Models/EntryDAO.php32
1 files changed, 31 insertions, 1 deletions
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 36d633c6e..50bd0584c 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -1274,7 +1274,7 @@ SQL;
/**
* @param array<string> $guids
- * @return int|false The number of affected feeds, or false if error
+ * @return int|false The number of affected entries, or false if error
*/
public function updateLastSeen(int $id_feed, array $guids, int $mtime = 0) {
if (count($guids) < 1) {
@@ -1308,6 +1308,36 @@ SQL;
}
}
+ /**
+ * Update (touch) the last seen attribute of the latest entries of a given feed.
+ * Useful when a feed is unchanged / cached.
+ * @return int|false The number of affected entries, or false in case of error
+ */
+ public function updateLastSeenUnchanged(int $id_feed, int $mtime = 0) {
+ $sql = <<<SQL
+UPDATE `_entry` SET `lastSeen` = :mtime
+WHERE id_feed = :id_feed1 AND `lastSeen` = (
+ SELECT max(e2.`lastSeen`) FROM `_entry` e2
+ WHERE e2.id_feed = :id_feed2
+)
+SQL;
+ $stm = $this->pdo->prepare($sql);
+ if ($mtime <= 0) {
+ $mtime = time();
+ }
+ if ($stm !== false &&
+ $stm->bindValue(':mtime', $mtime, PDO::PARAM_INT) &&
+ $stm->bindValue(':id_feed1', $id_feed, PDO::PARAM_INT) &&
+ $stm->bindValue(':id_feed2', $id_feed, PDO::PARAM_INT) &&
+ $stm->execute()) {
+ return $stm->rowCount();
+ } else {
+ $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info) . ' while updating feed ' . $id_feed);
+ return false;
+ }
+ }
+
/** @return array<string,int> */
public function countUnreadRead(): array {
$sql = <<<'SQL'