]> git.wh0rd.org Git - tt-rss.git/commitdiff
implement fallback _SIMPLE_UPDATE_MODE
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 22 Jan 2013 15:49:47 +0000 (19:49 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 22 Jan 2013 15:56:46 +0000 (19:56 +0400)
classes/rpc.php
include/functions.php
js/tt-rss.js

index 33e500edfe72eb12d6e94d0ab6dd31c86b1c7622..0e93cd32a346db50a6a196c7f49dca9235e50a8a 100644 (file)
@@ -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"));
+               }
+
+       }
+
 }
 ?>
index f3c05fecbf58134ece6e2f2c3ec1bd756e824e5f..089bbd8a0bf014de7edf5ef5be0fff15115e6edb 100644 (file)
                $params["csrf_token"] = $_SESSION["csrf_token"];
                $params["widescreen"] = (int) $_SESSION["widescreen"];
 
+               $params['simple_update'] = defined('_SIMPLE_UPDATE_MODE') && _SIMPLE_UPDATE_MODE;
+
                return $params;
        }
 
index b97c052c1a0f6f82acddde86e582620ee7c72452..d59ba495caa1de4d4b5d318d188a02c349c00659 100644 (file)
@@ -379,6 +379,11 @@ function init_second_stage() {
 
                console.log("second stage ok");
 
+               if (getInitParam("simple_update")) {
+                       console.log("scheduling simple feed updater...");
+                       window.setTimeout("update_random_feed()", 30*1000);
+               }
+
        } catch (e) {
                exception_error("init_second_stage", e);
        }
@@ -1033,3 +1038,19 @@ function switchPanelMode(wide) {
                exception_error("switchPanelMode", e);
        }
 }
+
+function update_random_feed() {
+       try {
+               console.log("in update_random_feed");
+
+               new Ajax.Request("backend.php", {
+                       parameters: "op=rpc&method=updateRandomFeed",
+                       onComplete: function(transport) {
+                               handle_rpc_json(transport, true);
+                               window.setTimeout("update_random_feed()", 30*1000);
+                       } });
+
+       } catch (e) {
+               exception_error("update_random_feed", e);
+       }
+}