X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=include%2Frssfuncs.php;h=01a11da6b535183096cb04158c82834575942160;hb=8292d05b7c9723bc91ccdf92f6acc5e46f58ce6c;hp=fcf89746111a35bbee6dde85a6124086b552b337;hpb=bca1cfbb9580d3ed295f7d93bbf4dce00eae8456;p=tt-rss.git diff --git a/include/rssfuncs.php b/include/rssfuncs.php index fcf89746..01a11da6 100644 --- a/include/rssfuncs.php +++ b/include/rssfuncs.php @@ -77,7 +77,6 @@ if (DB_TYPE == "pgsql") { $update_limit_qpart = "AND (( ttrss_feeds.update_interval = 0 - AND ttrss_user_prefs.value > 0 AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL) ) OR ( ttrss_feeds.update_interval > 0 @@ -87,7 +86,6 @@ } else { $update_limit_qpart = "AND (( ttrss_feeds.update_interval = 0 - AND ttrss_user_prefs.value > 0 AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE) ) OR ( ttrss_feeds.update_interval > 0 @@ -149,6 +147,8 @@ expire_cached_files($debug); expire_lock_files($debug); + $nf = 0; + // For each feed, we call the feed update function. foreach ($feeds_to_update as $feed) { if($debug) _debug("Base feed: $feed"); @@ -169,6 +169,7 @@ while ($tline = db_fetch_assoc($tmp_result)) { if($debug) _debug(" => " . $tline["last_updated"] . ", " . $tline["id"]); update_rss_feed($link, $tline["id"], true); + ++$nf; } } } @@ -178,6 +179,8 @@ // Send feed digests by email if needed. send_headlines_digests($link, $debug); + return $nf; + } // function update_daemon_common // ignore_daemon is not used @@ -241,6 +244,8 @@ $rss = false; $rss_hash = false; + $cache_timestamp = file_exists($cache_filename) ? filemtime($cache_filename) : 0; + $last_updated_timestamp = strtotime($last_updated); if (file_exists($cache_filename) && is_readable($cache_filename) && @@ -251,11 +256,18 @@ _debug("update_rss_feed: using local cache."); } - @$rss_data = file_get_contents($cache_filename); + if ($cache_timestamp > $last_updated_timestamp) { + @$rss_data = file_get_contents($cache_filename); - if ($rss_data) { - $rss_hash = sha1($rss_data); - @$rss = unserialize($rss_data); + if ($rss_data) { + $rss_hash = sha1($rss_data); + @$rss = unserialize($rss_data); + } + } else { + if ($debug_enabled) { + _debug("update_rss_feed: local cache valid and older than last_updated, nothing to do."); + } + return; } } @@ -263,11 +275,12 @@ if (!$feed_data) { if ($debug_enabled) { - _debug("update_rss_feed: fetching [$fetch_url]..."); + _debug("update_rss_feed: fetching [$fetch_url] (ts: $cache_timestamp/$last_updated_timestamp)"); } $feed_data = fetch_file_contents($fetch_url, false, - $auth_login, $auth_pass, false, $no_cache ? 15 : 45); + $auth_login, $auth_pass, false, $no_cache ? 15 : 45, + max($last_updated_timestamp, $cache_timestamp)); if ($debug_enabled) { _debug("update_rss_feed: fetch done."); @@ -277,12 +290,22 @@ if (!$feed_data) { global $fetch_last_error; + global $fetch_last_error_code; if ($debug_enabled) { - _debug("update_rss_feed: unable to fetch: $fetch_last_error"); + _debug("update_rss_feed: unable to fetch: $fetch_last_error [$fetch_last_error_code]"); } - $error_escaped = db_escape_string($link, $fetch_last_error); + $error_escaped = ''; + + // If-Modified-Since + if ($fetch_last_error_code != 304) { + $error_escaped = db_escape_string($link, $fetch_last_error); + } else { + if ($debug_enabled) { + _debug("update_rss_feed: source claims data not modified, nothing to do."); + } + } db_query($link, "UPDATE ttrss_feeds SET last_error = '$error_escaped',