summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-02-01 20:13:42 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-02-01 20:13:42 +0100
commit02d1dac0bb07884b79ddea20980bfcf21131f2d7 (patch)
tree1c004e5bbaf9cab501076547596f007906c46be0
parenta76e5bd1c65354dbdc9793179369ef0903d03762 (diff)
Rafraîchissement des flux en cache compatible multi-utilisateurs
Compatibilité multi-utilisateurs pour la mise à jour rapide des flux avec cache Correction de https://github.com/marienfressinaud/FreshRSS/commit/cf8ee6bd48221e73b515922e75945e9aa763f907#commitcomment-5247478 Contribue à https://github.com/marienfressinaud/FreshRSS/issues/351#issuecomment-31755012
-rw-r--r--app/Models/Feed.php8
-rw-r--r--app/Models/FeedDAO.php2
-rw-r--r--lib/SimplePie/SimplePie.php25
-rw-r--r--lib/SimplePie/SimplePie/Misc.php30
4 files changed, 21 insertions, 44 deletions
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 662476b7e..366c04c67 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -193,9 +193,9 @@ class FreshRSS_Feed extends Minz_Model {
}
$feed = customSimplePie();
$feed->set_feed_url ($url);
- $initResult = $feed->init ();
+ $mtime = $feed->init();
- if ((!$initResult) || $feed->error()) {
+ if ((!$mtime) || $feed->error()) {
throw new FreshRSS_Feed_Exception ($feed->error() . ' [' . $url . ']');
}
@@ -217,9 +217,11 @@ class FreshRSS_Feed extends Minz_Model {
$this->_description(html_only_entity_decode($feed->get_description()));
}
- if (($initResult == SIMPLEPIE_INIT_SUCCESS) || $loadDetails) {
+ if (($mtime === true) || ($mtime > $this->lastUpdate)) {
+ syslog(LOG_DEBUG, 'FreshRSS no cache ' . $mtime . ' > ' . $this->lastUpdate);
$this->loadEntries($feed); // et on charge les articles du flux
} else {
+ syslog(LOG_DEBUG, 'FreshRSS use cache for ' . $subscribe_url);
$this->entries = array();
}
}
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index a17ff0718..a2ce0e46f 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -199,7 +199,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
}
public function listFeedsOrderUpdate () {
- $sql = 'SELECT id, name, url, pathEntries, httpAuth, keep_history FROM `' . $this->prefix . 'feed` ORDER BY lastUpdate';
+ $sql = 'SELECT id, name, url, lastUpdate, pathEntries, httpAuth, keep_history FROM `' . $this->prefix . 'feed` ORDER BY lastUpdate';
$stm = $this->bd->prepare ($sql);
$stm->execute ();
diff --git a/lib/SimplePie/SimplePie.php b/lib/SimplePie/SimplePie.php
index 97b9310db..fe01d382e 100644
--- a/lib/SimplePie/SimplePie.php
+++ b/lib/SimplePie/SimplePie.php
@@ -402,9 +402,6 @@ define('SIMPLEPIE_FILE_SOURCE_CURL', 8);
*/
define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
-define('SIMPLEPIE_INIT_FAIL', 0); //FreshRSS
-define('SIMPLEPIE_INIT_SUCCESS', 1); //FreshRSS
-define('SIMPLEPIE_INIT_CACHE', 2); //FreshRSS
/**
@@ -1222,14 +1219,14 @@ class SimplePie
* configuration options get processed, feeds are fetched, cached, and
* parsed, and all of that other good stuff.
*
- * @return boolean True if successful, false otherwise
+ * @return positive integer with modification time if using cache, boolean true if otherwise successful, false otherwise
*/
public function init()
{
// Check absolute bare minimum requirements.
if (!extension_loaded('xml') || !extension_loaded('pcre'))
{
- return SIMPLEPIE_INIT_FAIL;
+ return false;
}
// Then check the xml extension is sane (i.e., libxml 2.7.x issue on PHP < 5.2.9 and libxml 2.7.0 to 2.7.2 on any version) if we don't have xmlreader.
elseif (!extension_loaded('xmlreader'))
@@ -1244,7 +1241,7 @@ class SimplePie
}
if (!$xml_is_sane)
{
- return SIMPLEPIE_INIT_FAIL;
+ return false;
}
}
@@ -1276,11 +1273,11 @@ class SimplePie
}
$i++;
}
- return inval($success);
+ return (bool) $success;
}
elseif ($this->feed_url === null && $this->raw_data === null)
{
- return SIMPLEPIE_INIT_FAIL;
+ return false;
}
$this->error = null;
@@ -1301,10 +1298,10 @@ class SimplePie
// Fetch the data via SimplePie_File into $this->raw_data
if (($fetched = $this->fetch_data($cache)) === true)
{
- return SIMPLEPIE_INIT_CACHE;
+ return $this->data['mtime']; //FreshRSS
}
elseif ($fetched === false) {
- return SIMPLEPIE_INIT_FAIL;
+ return false;
}
list($headers, $sniffed) = $fetched;
@@ -1381,7 +1378,7 @@ class SimplePie
{
$this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
$this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
- return SIMPLEPIE_INIT_FAIL;
+ return false;
}
if (isset($headers))
@@ -1389,13 +1386,14 @@ class SimplePie
$this->data['headers'] = $headers;
}
$this->data['build'] = SIMPLEPIE_BUILD;
+ $this->data['mtime'] = time(); //FreshRSS
// Cache the file if caching is enabled
if ($cache && !$cache->save($this))
{
trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
}
- return SIMPLEPIE_INIT_SUCCESS;
+ return true;
}
}
}
@@ -1412,7 +1410,7 @@ class SimplePie
$this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
- return SIMPLEPIE_INIT_FAIL;
+ return false;
}
/**
@@ -1558,6 +1556,7 @@ class SimplePie
if ($cache)
{
$this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
+ $this->data['mtime'] = time(); //FreshRSS
if (!$cache->save($this))
{
trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
diff --git a/lib/SimplePie/SimplePie/Misc.php b/lib/SimplePie/SimplePie/Misc.php
index 347520303..b5812473b 100644
--- a/lib/SimplePie/SimplePie/Misc.php
+++ b/lib/SimplePie/SimplePie/Misc.php
@@ -2161,36 +2161,12 @@ function embed_wmedia(width, height, link) {
/**
* Get the SimplePie build timestamp
*
- * Uses the git index if it exists, otherwise uses the modification time
- * of the newest file.
+ * Return SimplePie.php modification time.
*/
public static function get_build()
{
- $root = dirname(dirname(__FILE__));
- if (file_exists($root . '/.git/index'))
- {
- return filemtime($root . '/.git/index');
- }
- elseif (file_exists($root . '/SimplePie'))
- {
- $time = 0;
- foreach (glob($root . '/SimplePie/*.php') as $file)
- {
- if (($mtime = filemtime($file)) > $time)
- {
- $time = $mtime;
- }
- }
- return $time;
- }
- elseif (file_exists(dirname(__FILE__) . '/Core.php'))
- {
- return filemtime(dirname(__FILE__) . '/Core.php');
- }
- else
- {
- return filemtime(__FILE__);
- }
+ $mtime = @filemtime(dirname(dirname(__FILE__)) . '/SimplePie.php'); //FreshRSS
+ return $mtime ? $mtime : filemtime(__FILE__);
}
/**