summaryrefslogtreecommitdiff
path: root/classes/rpc.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-01-22 19:49:47 +0400
committerAndrew Dolgov <[email protected]>2013-01-22 19:56:46 +0400
commit8b83bf5fa15cd0acf85d9d34a113ca6cecd3106b (patch)
tree5940748eeb25101a7edd9d4d5be3c91c6743cb08 /classes/rpc.php
parent6addc13f46c29674bdf82986319f1aad8abf50cd (diff)
implement fallback _SIMPLE_UPDATE_MODE
Diffstat (limited to 'classes/rpc.php')
-rw-r--r--classes/rpc.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/classes/rpc.php b/classes/rpc.php
index 33e500edf..0e93cd32a 100644
--- a/classes/rpc.php
+++ b/classes/rpc.php
@@ -645,5 +645,76 @@ class RPC extends Handler_Protected {
print json_encode(array("wide" => $wide));
}
+ function updaterandomfeed() {
+ // Test if the feed need a update (update interval exceded).
+ if (DB_TYPE == "pgsql") {
+ $update_limit_qpart = "AND ((
+ ttrss_feeds.update_interval = 0
+ AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL)
+ ) OR (
+ ttrss_feeds.update_interval > 0
+ AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL)
+ ) OR ttrss_feeds.last_updated IS NULL
+ OR last_updated = '1970-01-01 00:00:00')";
+ } else {
+ $update_limit_qpart = "AND ((
+ ttrss_feeds.update_interval = 0
+ AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE)
+ ) OR (
+ ttrss_feeds.update_interval > 0
+ AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE)
+ ) OR ttrss_feeds.last_updated IS NULL
+ OR last_updated = '1970-01-01 00:00:00')";
+ }
+
+ // Test if feed is currently being updated by another process.
+ if (DB_TYPE == "pgsql") {
+ $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')";
+ } else {
+ $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))";
+ }
+
+ $random_qpart = sql_random_function();
+
+ // We search for feed needing update.
+ $result = db_query($this->link, "SELECT ttrss_feeds.feed_url,ttrss_feeds.id
+ FROM
+ ttrss_feeds, ttrss_users, ttrss_user_prefs
+ WHERE
+ ttrss_feeds.owner_uid = ttrss_users.id
+ AND ttrss_users.id = ttrss_user_prefs.owner_uid
+ AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL'
+ AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]."
+ $update_limit_qpart $updstart_thresh_qpart
+ ORDER BY $random_qpart LIMIT 30");
+
+ $feed_id = -1;
+
+ require_once "rssfuncs.php";
+
+ $num_updated = 0;
+
+ $tstart = time();
+
+ while ($line = db_fetch_assoc($result)) {
+ $feed_id = $line["id"];
+
+ if (time() - $tstart < 30) {
+ update_rss_feed($this->link, $feed_id, true);
+ ++$num_updated;
+ } else {
+ break;
+ }
+ }
+
+ if ($num_updated > 0) {
+ print json_encode(array("message" => "UPDATE_COUNTERS",
+ "num_updated" => $num_updated));
+ } else {
+ print json_encode(array("message" => "NOTHING_TO_UPDATE"));
+ }
+
+ }
+
}
?>