Преглед на файлове

Fix last update & archive logic (#4422)

#fix https://github.com/FreshRSS/FreshRSS/issues/4401
Alexandre Alapetite преди 3 години
родител
ревизия
07a52137a9
променени са 2 файла, в които са добавени 13 реда и са изтрити 7 реда
  1. 7 7
      app/Controllers/feedController.php
  2. 6 0
      app/Models/EntryDAO.php

+ 7 - 7
app/Controllers/feedController.php

@@ -361,6 +361,8 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
 				}
 				//Minz_Log::debug($feed->url(false) . ' was updated at ' . date('c', $mtime) . ' by another user');
 				//Will take advantage of the newer cache
+			} else {
+				$mtime = time();
 			}
 
 			if (!$feed->lock()) {
@@ -413,9 +415,9 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
 
 				// For this feed, check existing GUIDs already in database.
 				$existingHashForGuids = $entryDAO->listHashForFeedGuids($feed->id(), $newGuids);
-				$newGuids = array();
+				/** @var array<string,bool> */
+				$newGuids = [];
 
-				$oldGuids = array();
 				// Add entries in database if possible.
 				/** @var FreshRSS_Entry $entry */
 				foreach ($entries as $entry) {
@@ -426,10 +428,8 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
 
 					if (isset($existingHashForGuids[$entry->guid()])) {
 						$existingHash = $existingHashForGuids[$entry->guid()];
-						if (strcasecmp($existingHash, $entry->hash()) === 0) {
-							//This entry already exists and is unchanged.
-							$oldGuids[] = $entry->guid();
-						} else {	//This entry already exists but has been updated
+						if (strcasecmp($existingHash, $entry->hash()) !== 0) {
+							//This entry already exists but has been updated
 							//Minz_Log::debug('Entry with GUID `' . $entry->guid() . '` updated in feed ' . $feed->url(false) .
 								//', old hash ' . $existingHash . ', new hash ' . $entry->hash());
 							$entry->_isRead($mark_updated_article_unread ? false : null);	//Change is_read according to policy.
@@ -488,7 +488,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
 						$nb_new_articles++;
 					}
 				}
-				$entryDAO->updateLastSeen($feed->id(), $oldGuids, $mtime);
+				$entryDAO->updateLastSeen($feed->id(), array_keys($newGuids), $mtime);
 			}
 			unset($entries);
 

+ 6 - 0
app/Models/EntryDAO.php

@@ -1170,6 +1170,12 @@ SQL;
 		}
 	}
 
+	/**
+	 * @param int $id_feed
+	 * @param array<string> $guids
+	 * @param int $mtime
+	 * @return int|false The number of affected feeds, or false if error
+	 */
 	public function updateLastSeen($id_feed, $guids, $mtime = 0) {
 		if (count($guids) < 1) {
 			return 0;