Jelajahi Sumber

No old ID (#2276)

* No old ID

https://github.com/FreshRSS/FreshRSS/issues/2273

* PostgreSQL insert or ignore
Alexandre Alapetite 7 tahun lalu
induk
melakukan
834ffacce2

+ 3 - 7
app/Controllers/feedController.php

@@ -377,17 +377,13 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 						$read_upon_reception = $feed->attributes('read_upon_reception') !== null ? (
 								$feed->attributes('read_upon_reception')
 							) : FreshRSS_Context::$user_conf->mark_when['reception'];
-						if ($isNewFeed) {
-							$id = min(time(), $entry_date) . uSecString();
-							$entry->_isRead($read_upon_reception);
-						} elseif ($entry_date < $date_min) {
-							$id = min(time(), $entry_date) . uSecString();
+						$id = uTimeString();
+						$entry->_id($id);
+						if ($entry_date < $date_min) {
 							$entry->_isRead(true);	//Old article that was not in database. Probably an error, so mark as read
 						} else {
-							$id = uTimeString();
 							$entry->_isRead($read_upon_reception);
 						}
-						$entry->_id($id);
 
 						$entry = Minz_ExtensionManager::callHook('entry_before_insert', $entry);
 						if ($entry === null) {

+ 1 - 1
app/Controllers/importExportController.php

@@ -585,7 +585,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
 				$feed_id, $item['id'], $item['title'], $author,
 				$content, $url, $published, $is_read, $is_starred
 			);
-			$entry->_id(min(time(), $entry->date(true)) . uSecString());
+			$entry->_id(uTimeString());
 			$entry->_tags($tags);
 
 			if (isset($newGuids[$entry->guid()])) {

+ 3 - 1
app/Models/EntryDAOPGSQL.php

@@ -37,7 +37,9 @@ BEGIN
 	INSERT INTO `' . $this->prefix . 'entry` (id, guid, title, author, content, link, date, `lastSeen`, hash, is_read, is_favorite, id_feed, tags)
 		(SELECT rank + row_number() OVER(ORDER BY date) AS id, guid, title, author, content, link, date, `lastSeen`, hash, is_read, is_favorite, id_feed, tags
 			FROM `' . $this->prefix . 'entrytmp` AS etmp
-			WHERE NOT EXISTS (SELECT 1 FROM `' . $this->prefix . 'entry` AS ereal WHERE etmp.id_feed = ereal.id_feed AND etmp.guid = ereal.guid)
+			WHERE NOT EXISTS (
+				SELECT 1 FROM `' . $this->prefix . 'entry` AS ereal
+				WHERE (etmp.id = ereal.id) OR (etmp.id_feed = ereal.id_feed AND etmp.guid = ereal.guid))
 			ORDER BY date);
 	DELETE FROM `' . $this->prefix . 'entrytmp` WHERE id <= maxrank;
 END $$;';

+ 1 - 6
lib/lib_rss.php

@@ -303,12 +303,7 @@ function lazyimg($content) {
 
 function uTimeString() {
 	$t = @gettimeofday();
-	return $t['sec'] . str_pad($t['usec'], 6, '0');
-}
-
-function uSecString() {
-	$t = @gettimeofday();
-	return str_pad($t['usec'], 6, '0');
+	return $t['sec'] . str_pad($t['usec'], 6, '0', STR_PAD_LEFT);
 }
 
 function invalidateHttpCache($username = '') {