Sfoglia il codice sorgente

Fix markAsReadUponGone regression (#6663)

Regression from https://github.com/FreshRSS/FreshRSS/pull/5470
Was not working anymore when the feed was empty.
Plus simplification of the logic when the feed is not empty
Alexandre Alapetite 1 anno fa
parent
commit
5659b37948
3 ha cambiato i file con 10 aggiunte e 15 eliminazioni
  1. 1 1
      app/Controllers/feedController.php
  2. 5 5
      app/Models/Feed.php
  3. 4 9
      app/Models/FeedDAO.php

+ 1 - 1
app/Controllers/feedController.php

@@ -515,7 +515,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
 				} else {
 					$newGuids = $feed->loadGuids($simplePie);
 					$entries = $feed->loadEntries($simplePie);
-					$feedIsEmpty = $simplePiePush !== null && empty($newGuids);
+					$feedIsEmpty = $simplePiePush === null && empty($newGuids);
 					$feedIsUnchanged = false;
 				}
 				$mtime = $feed->cacheModifiedTime() ?: time();

+ 5 - 5
app/Models/Feed.php

@@ -843,7 +843,7 @@ class FreshRSS_Feed extends Minz_Model {
 	 * Remember to call `updateCachedValues($id_feed)` or `updateCachedValues()` just after.
 	 * @return int|false the number of lines affected, or false if not applicable
 	 */
-	public function markAsReadUponGone(bool $upstreamIsEmpty, int $maxTimestamp = 0) {
+	public function markAsReadUponGone(bool $upstreamIsEmpty, int $minLastSeen = 0) {
 		$readUponGone = $this->attributeBoolean('read_upon_gone');
 		if ($readUponGone === null) {
 			$readUponGone = FreshRSS_Context::userConf()->mark_when['gone'];
@@ -852,14 +852,14 @@ class FreshRSS_Feed extends Minz_Model {
 			return false;
 		}
 		if ($upstreamIsEmpty) {
-			if ($maxTimestamp <= 0) {
-				$maxTimestamp = time();
+			if ($minLastSeen <= 0) {
+				$minLastSeen = time();
 			}
 			$entryDAO = FreshRSS_Factory::createEntryDao();
-			$affected = $entryDAO->markReadFeed($this->id(), $maxTimestamp . '000000');
+			$affected = $entryDAO->markReadFeed($this->id(), $minLastSeen . '000000');
 		} else {
 			$feedDAO = FreshRSS_Factory::createFeedDao();
-			$affected = $feedDAO->markAsReadUponGone($this->id());
+			$affected = $feedDAO->markAsReadNotSeen($this->id(), $minLastSeen);
 		}
 		if ($affected > 0) {
 			Minz_Log::debug(__METHOD__ . " $affected items" . ($upstreamIsEmpty ? ' (all)' : '') . ' [' . $this->url(false) . ']');

+ 4 - 9
app/Models/FeedDAO.php

@@ -509,20 +509,15 @@ SQL;
 	 * Remember to call updateCachedValues() after calling this function
 	 * @return int|false number of lines affected or false in case of error
 	 */
-	public function markAsReadUponGone(int $id) {
-		//Double SELECT for MySQL workaround ERROR 1093 (HY000)
+	public function markAsReadNotSeen(int $id, int $minLastSeen) {
 		$sql = <<<'SQL'
 UPDATE `_entry` SET is_read=1
-WHERE id_feed=:id_feed1 AND is_read=0 AND (
-	`lastSeen` + 60 < (SELECT s1.maxlastseen FROM (
-		SELECT MAX(e2.`lastSeen`) AS maxlastseen FROM `_entry` e2 WHERE e2.id_feed = :id_feed2
-	) s1)
-)
+WHERE id_feed=:id_feed AND is_read=0 AND (`lastSeen` + 10 < :min_last_seen)
 SQL;
 
 		if (($stm = $this->pdo->prepare($sql)) &&
-			$stm->bindParam(':id_feed1', $id, PDO::PARAM_INT) &&
-			$stm->bindParam(':id_feed2', $id, PDO::PARAM_INT) &&
+			$stm->bindValue(':id_feed', $id, PDO::PARAM_INT) &&
+			$stm->bindValue(':min_last_seen', $minLastSeen, PDO::PARAM_INT) &&
 			$stm->execute()) {
 			return $stm->rowCount();
 		} else {