cache simplepie object instead of xml feed data
This commit is contained in:
parent
d5974daa33
commit
4f9cbdff1d
|
@ -149,7 +149,6 @@
|
|||
if($debug) _debug("Feed: " . $line["feed_url"] . ", " . $line["last_updated"]);
|
||||
|
||||
update_rss_feed($link, $line["id"], true);
|
||||
sleep(1); // prevent flood (FIXME make this an option?)
|
||||
}
|
||||
|
||||
require_once "digest.php";
|
||||
|
@ -205,7 +204,7 @@
|
|||
|
||||
$date_feed_processed = date('Y-m-d H:i');
|
||||
|
||||
$cache_filename = CACHE_DIR . "/simplepie/" . sha1($fetch_url) . ".xml";
|
||||
$cache_filename = CACHE_DIR . "/simplepie/" . sha1($fetch_url) . ".feed";
|
||||
|
||||
// Ignore cache if new feed or manual update.
|
||||
$cache_age = ($no_cache || is_null($last_updated) || $last_updated == '1970-01-01 00:00:00') ?
|
||||
|
@ -218,6 +217,9 @@
|
|||
|
||||
$cached_feed_data_hash = false;
|
||||
|
||||
$rss = false;
|
||||
$rss_hash = false;
|
||||
|
||||
if (file_exists($cache_filename) &&
|
||||
is_readable($cache_filename) &&
|
||||
!$auth_login && !$auth_pass &&
|
||||
|
@ -227,9 +229,15 @@
|
|||
_debug("update_rss_feed: using local cache.");
|
||||
}
|
||||
|
||||
$feed_data = file_get_contents($cache_filename);
|
||||
$cached_feed_data_hash = sha1($feed_data);
|
||||
@$rss_data = file_get_contents($cache_filename);
|
||||
|
||||
if ($rss_data) {
|
||||
$rss_hash = sha1($rss_data);
|
||||
@$rss = unserialize($rss_data);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$rss) {
|
||||
|
||||
if (!$feed_data) {
|
||||
if ($debug_enabled) {
|
||||
|
@ -238,6 +246,11 @@
|
|||
|
||||
$feed_data = fetch_file_contents($fetch_url, false,
|
||||
$auth_login, $auth_pass, false, $no_cache ? 15 : 45);
|
||||
|
||||
if ($debug_enabled) {
|
||||
_debug("update_rss_feed: fetch done.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!$feed_data) {
|
||||
|
@ -255,17 +268,6 @@
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
// cache data for later
|
||||
if (!$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/simplepie")) {
|
||||
if (sha1($feed_data) != $cached_feed_data_hash) {
|
||||
|
||||
if ($debug_enabled) {
|
||||
_debug("update_rss_feed: saving $cache_filename");
|
||||
}
|
||||
|
||||
@file_put_contents($cache_filename, $feed_data);
|
||||
}
|
||||
}
|
||||
|
||||
$pluginhost = new PluginHost($link);
|
||||
|
@ -280,10 +282,7 @@
|
|||
$feed_data = $plugin->hook_feed_fetched($feed_data);
|
||||
}
|
||||
|
||||
if ($debug_enabled) {
|
||||
_debug("update_rss_feed: fetch done, parsing...");
|
||||
}
|
||||
|
||||
if (!$rss) {
|
||||
$rss = new SimplePie();
|
||||
$rss->set_sanitize_class("SanitizeDummy");
|
||||
// simplepie ignores the above and creates default sanitizer anyway,
|
||||
|
@ -294,6 +293,7 @@
|
|||
$rss->enable_cache(false);
|
||||
|
||||
@$rss->init();
|
||||
}
|
||||
|
||||
// print_r($rss);
|
||||
|
||||
|
@ -301,6 +301,19 @@
|
|||
|
||||
if (!$rss->error()) {
|
||||
|
||||
// cache data for later
|
||||
if (!$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/simplepie")) {
|
||||
$rss_data = serialize($rss);
|
||||
$new_rss_hash = sha1($rss_data);
|
||||
|
||||
if ($new_rss_hash != $rss_hash) {
|
||||
if ($debug_enabled) {
|
||||
_debug("update_rss_feed: saving $cache_filename");
|
||||
}
|
||||
@file_put_contents($cache_filename, serialize($rss));
|
||||
}
|
||||
}
|
||||
|
||||
// We use local pluginhost here because we need to load different per-user feed plugins
|
||||
$pluginhost->run_hooks($pluginhost::HOOK_FEED_PARSED, "hook_feed_parsed", $rss);
|
||||
|
||||
|
|
Loading…
Reference in New Issue