Parcourir la source

Better multiuser update

Alexandre Alapetite il y a 9 ans
Parent
commit
fe65eec5bb
2 fichiers modifiés avec 12 ajouts et 7 suppressions
  1. 5 4
      app/Controllers/feedController.php
  2. 7 3
      app/Models/FeedDAO.php

+ 5 - 4
app/Controllers/feedController.php

@@ -271,13 +271,14 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 			if ($ttl == -1) {
 				continue;	//Feed refresh is disabled
 			}
-			if ($feed->lastUpdate() < time() + 60 - ($ttl == -2 ? FreshRSS_Context::$user_conf->ttl_default : $ttl)) {
+			if ($feed->lastUpdate() + 10 >= time() - ($ttl == -2 ? FreshRSS_Context::$user_conf->ttl_default : $ttl)) {
 				//Too early to refresh from source, but check whether the feed was updated by another user
 				$mtime = $feed->cacheModifiedTime();
-				if ($feed->lastUpdate() >= $mtime + 10) {
+				if ($feed->lastUpdate() + 10 >= $mtime) {
 					continue;	//Nothing newer from other users
 				}
-				Minz_Log::debug($feed->url() . ' was recently updated by another user');
+				//Minz_Log::debug($feed->url() . ' was updated at ' . date('c', $mtime) . ' by another user');
+				//Will take advantage of the newer cache
 			}
 
 			if (!$feed->lock()) {
@@ -391,7 +392,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 				}
 			}
 
-			$feedDAO->updateLastUpdate($feed->id(), 0, $entryDAO->inTransaction());
+			$feedDAO->updateLastUpdate($feed->id(), false, $entryDAO->inTransaction(), $mtime);
 			if ($entryDAO->inTransaction()) {
 				$entryDAO->commit();
 			}

+ 7 - 3
app/Models/FeedDAO.php

@@ -82,7 +82,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
 		}
 	}
 
-	public function updateLastUpdate($id, $inError = 0, $updateCache = true) {
+	public function updateLastUpdate($id, $inError = false, $updateCache = true, $mtime = 0) {
 		if ($updateCache) {
 			$sql = 'UPDATE `' . $this->prefix . 'feed` '	//2 sub-requests with FOREIGN KEY(e.id_feed), INDEX(e.is_read) faster than 1 request with GROUP BY or CASE
 			     . 'SET `cache_nbEntries`=(SELECT COUNT(e1.id) FROM `' . $this->prefix . 'entry` e1 WHERE e1.id_feed=`' . $this->prefix . 'feed`.id),'
@@ -95,9 +95,13 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
 			     . 'WHERE id=?';
 		}
 
+		if ($mtime <= 0) {
+			$mtime = time();
+		}
+
 		$values = array(
-			time(),
-			$inError,
+			$mtime,
+			$inError ? 1 : 0,
 			$id,
 		);