update_rss_feed: handle multiple feeds with the same URL at once
This commit is contained in:
parent
6e4f0519b7
commit
c633e370ec
3 changed files with 71 additions and 57 deletions
|
@ -379,14 +379,7 @@
|
|||
case "updateFeed":
|
||||
$feed_id = db_escape_string($_REQUEST["feed_id"]);
|
||||
|
||||
$result = db_query($link,
|
||||
"SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
|
||||
AND owner_uid = " . $_SESSION["uid"]);
|
||||
|
||||
if (db_num_rows($result) > 0) {
|
||||
$feed_url = db_fetch_result($result, 0, "feed_url");
|
||||
update_rss_feed($link, $feed_url, $feed_id);
|
||||
}
|
||||
update_rss_feed($link, $feed_id, true);
|
||||
|
||||
print json_encode(array("status" => "OK"));
|
||||
|
||||
|
|
|
@ -508,7 +508,26 @@
|
|||
|
||||
}
|
||||
|
||||
function update_rss_feed($link, $feed_url, $feed, $ignore_daemon = false) {
|
||||
function update_rss_feed($link, $feed, $ignore_daemon = false) {
|
||||
|
||||
global $memcache;
|
||||
|
||||
/* Update all feeds with the same URL to utilize memcache */
|
||||
|
||||
if ($memcache) {
|
||||
$result = db_query($link, "SELECT f1.id
|
||||
FROM ttrss_feeds AS f1, ttrss_feeds AS f2
|
||||
WHERE f2.feed_url = f1.feed_url AND f2.id = '$feed'");
|
||||
|
||||
while ($line = db_fetch_assoc($result)) {
|
||||
update_rss_feed_real($link, $line["id"], $ignore_daemon);
|
||||
}
|
||||
} else {
|
||||
update_rss_feed_real($link, $feed, $ignore_daemon);
|
||||
}
|
||||
}
|
||||
|
||||
function update_rss_feed_real($link, $feed, $ignore_daemon = false) {
|
||||
|
||||
global $memcache;
|
||||
|
||||
|
@ -535,14 +554,14 @@
|
|||
} else {
|
||||
|
||||
$result = db_query($link, "SELECT id,update_interval,auth_login,
|
||||
auth_pass,cache_images,update_method,last_updated
|
||||
feed_url,auth_pass,cache_images,update_method,last_updated
|
||||
FROM ttrss_feeds WHERE id = '$feed'");
|
||||
|
||||
}
|
||||
|
||||
if (db_num_rows($result) == 0) {
|
||||
if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
|
||||
_debug("update_rss_feed: feed $feed [$feed_url] NOT FOUND/SKIPPED");
|
||||
_debug("update_rss_feed: feed $feed NOT FOUND/SKIPPED");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -577,13 +596,12 @@
|
|||
|
||||
$update_interval = db_fetch_result($result, 0, "update_interval");
|
||||
$cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
|
||||
$fetch_url = db_fetch_result($result, 0, "feed_url");
|
||||
|
||||
if ($update_interval < 0) { return; }
|
||||
|
||||
$feed = db_escape_string($feed);
|
||||
|
||||
$fetch_url = $feed_url;
|
||||
|
||||
if ($auth_login && $auth_pass) {
|
||||
$url_parts = array();
|
||||
preg_match("/(^[^:]*):\/\/(.*)/", $fetch_url, $url_parts);
|
||||
|
@ -602,6 +620,18 @@
|
|||
error_reporting(0);
|
||||
}
|
||||
|
||||
$obj_id = md5("FDATA:$fetch_url");
|
||||
|
||||
if ($memcache && $obj = $memcache->get($obj_id)) {
|
||||
|
||||
if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
|
||||
_debug("update_rss_feed: data found in memcache.");
|
||||
}
|
||||
|
||||
$rss = $obj;
|
||||
|
||||
} else {
|
||||
|
||||
if (!$use_simplepie) {
|
||||
$rss = fetch_rss($fetch_url);
|
||||
} else {
|
||||
|
@ -636,6 +666,8 @@
|
|||
$rss->init();
|
||||
}
|
||||
|
||||
if ($memcache && $rss) $memcache->add($obj_id, $rss, 0, 300);
|
||||
}
|
||||
|
||||
// print_r($rss);
|
||||
|
||||
|
@ -2398,20 +2430,16 @@
|
|||
$cat_qpart = "cat_id IS NULL";
|
||||
}
|
||||
|
||||
$tmp_result = db_query($link, "SELECT id,feed_url FROM ttrss_feeds
|
||||
$tmp_result = db_query($link, "SELECT id FROM ttrss_feeds
|
||||
WHERE $cat_qpart AND owner_uid = " . $_SESSION["uid"]);
|
||||
|
||||
while ($tmp_line = db_fetch_assoc($tmp_result)) {
|
||||
$feed_url = $tmp_line["feed_url"];
|
||||
$feed_id = $tmp_line["id"];
|
||||
update_rss_feed($link, $feed_url, $feed_id, $force_update);
|
||||
update_rss_feed($link, $feed_id, $force_update);
|
||||
}
|
||||
|
||||
} else {
|
||||
$tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
|
||||
WHERE id = '$feed'");
|
||||
$feed_url = db_fetch_result($tmp_result, 0, "feed_url");
|
||||
update_rss_feed($link, $feed_url, $feed, $force_update);
|
||||
update_rss_feed($link, $feed, $force_update);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2931,7 +2959,7 @@
|
|||
$feed_id = db_fetch_result($result, 0, "id");
|
||||
|
||||
if ($feed_id) {
|
||||
update_rss_feed($link, $url, $feed_id, true);
|
||||
update_rss_feed($link, $feed_id, true);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -5833,7 +5861,7 @@
|
|||
// We setup a alarm to alert if the feed take more than 300s to update.
|
||||
// => HANG alarm.
|
||||
if(!$from_http && function_exists('pcntl_alarm')) pcntl_alarm(300);
|
||||
update_rss_feed($link, $line["feed_url"], $line["id"], true);
|
||||
update_rss_feed($link, $line["id"], true);
|
||||
// Cancel the alarm (the update went well)
|
||||
if(!$from_http && function_exists('pcntl_alarm')) pcntl_alarm(0);
|
||||
|
||||
|
|
|
@ -286,14 +286,7 @@
|
|||
if ($subop == "updateFeed") {
|
||||
$feed_id = db_escape_string($_REQUEST["feed"]);
|
||||
|
||||
$result = db_query($link,
|
||||
"SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
|
||||
AND owner_uid = " . $_SESSION["uid"]);
|
||||
|
||||
if (db_num_rows($result) > 0) {
|
||||
$feed_url = db_fetch_result($result, 0, "feed_url");
|
||||
update_rss_feed($link, $feed_url, $feed_id);
|
||||
}
|
||||
update_rss_feed($link, $feed_id);
|
||||
|
||||
print "<rpc-reply>";
|
||||
print "<counters>";
|
||||
|
|
Loading…
Reference in a new issue