subscribe_to_feed: use already fetched data when updating initially

This commit is contained in:
Andrew Dolgov 2013-05-07 15:34:20 +04:00
parent d29357fa02
commit 23923fb29b
2 changed files with 47 additions and 46 deletions

View File

@ -1661,7 +1661,7 @@
$feed_id = db_fetch_result($result, 0, "id"); $feed_id = db_fetch_result($result, 0, "id");
if ($feed_id) { if ($feed_id) {
update_rss_feed($feed_id, true); update_rss_feed($feed_id, false, false, false, $contents);
} }
return array("code" => 1); return array("code" => 1);

View File

@ -191,7 +191,7 @@
// ignore_daemon is not used // ignore_daemon is not used
function update_rss_feed($feed, $ignore_daemon = false, $no_cache = false, function update_rss_feed($feed, $ignore_daemon = false, $no_cache = false,
$override_url = false) { $override_url = false, $override_data = false) {
$debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']; $debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug'];
@ -251,7 +251,11 @@
$force_refetch = isset($_REQUEST["force_refetch"]); $force_refetch = isset($_REQUEST["force_refetch"]);
if (file_exists($cache_filename) && if ($override_data) {
$feed_data = $override_data;
}
if (!$feed_data && file_exists($cache_filename) &&
is_readable($cache_filename) && is_readable($cache_filename) &&
!$auth_login && !$auth_pass && !$auth_login && !$auth_pass &&
filemtime($cache_filename) > time() - 30) { filemtime($cache_filename) > time() - 30) {
@ -268,69 +272,66 @@
_debug("local cache will not be used for this feed", $debug_enabled); _debug("local cache will not be used for this feed", $debug_enabled);
} }
if (!$rss) { if (!$feed_data) {
_debug("fetching [$fetch_url]...", $debug_enabled);
_debug("If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T', $last_article_timestamp), $debug_enabled);
if (!$feed_data) { $feed_data = fetch_file_contents($fetch_url, false,
_debug("fetching [$fetch_url]...", $debug_enabled); $auth_login, $auth_pass, false,
_debug("If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T', $last_article_timestamp), $debug_enabled); $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT,
$force_refetch ? 0 : $last_article_timestamp);
$feed_data = fetch_file_contents($fetch_url, false, global $fetch_curl_used;
$auth_login, $auth_pass, false,
$no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT,
$force_refetch ? 0 : $last_article_timestamp);
global $fetch_curl_used; if (!$fetch_curl_used) {
$tmp = @gzdecode($feed_data);
if (!$fetch_curl_used) { if ($tmp) $feed_data = $tmp;
$tmp = @gzdecode($feed_data); }
if ($tmp) $feed_data = $tmp; $feed_data = trim($feed_data);
}
$feed_data = trim($feed_data); _debug("fetch done.", $debug_enabled);
_debug("fetch done.", $debug_enabled); if ($feed_data) {
$error = verify_feed_xml($feed_data);
if ($feed_data) { if ($error) {
$error = verify_feed_xml($feed_data); _debug("error verifying XML, code: " . $error->code, $debug_enabled);
if ($error) { if ($error->code == 26) {
_debug("error verifying XML, code: " . $error->code, $debug_enabled); _debug("got error 26, trying to decode entities...", $debug_enabled);
if ($error->code == 26) { $feed_data = html_entity_decode($feed_data, ENT_COMPAT, 'UTF-8');
_debug("got error 26, trying to decode entities...", $debug_enabled);
$feed_data = html_entity_decode($feed_data, ENT_COMPAT, 'UTF-8'); $error = verify_feed_xml($feed_data);
$error = verify_feed_xml($feed_data); if ($error) $feed_data = '';
if ($error) $feed_data = '';
}
} }
} }
} }
}
if (!$feed_data) { if (!$feed_data) {
global $fetch_last_error; global $fetch_last_error;
global $fetch_last_error_code; global $fetch_last_error_code;
_debug("unable to fetch: $fetch_last_error [$fetch_last_error_code]", $debug_enabled); _debug("unable to fetch: $fetch_last_error [$fetch_last_error_code]", $debug_enabled);
$error_escaped = ''; $error_escaped = '';
// If-Modified-Since // If-Modified-Since
if ($fetch_last_error_code != 304) { if ($fetch_last_error_code != 304) {
$error_escaped = db_escape_string($fetch_last_error); $error_escaped = db_escape_string($fetch_last_error);
} else { } else {
_debug("source claims data not modified, nothing to do.", $debug_enabled); _debug("source claims data not modified, nothing to do.", $debug_enabled);
}
db_query(
"UPDATE ttrss_feeds SET last_error = '$error_escaped',
last_updated = NOW() WHERE id = '$feed'");
return;
} }
db_query(
"UPDATE ttrss_feeds SET last_error = '$error_escaped',
last_updated = NOW() WHERE id = '$feed'");
return;
} }
$pluginhost = new PluginHost(); $pluginhost = new PluginHost();