]> git.wh0rd.org Git - tt-rss.git/commitdiff
offline: smarter detection of articles to download; purge old data
authorAndrew Dolgov <fox@bah.org.ru>
Tue, 3 Feb 2009 19:54:24 +0000 (22:54 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Tue, 3 Feb 2009 19:54:24 +0000 (22:54 +0300)
modules/backend-rpc.php
tt-rss.js

index 3042703caa05f2f94ac3679457fe3c579686d986..dd6ea2694f11c5f247662eb253ee3a747644ef36 100644 (file)
 
                if ($subop == "download") {
                        $stage = (int) $_REQUEST["stage"];
-                       $cid = db_escape_string($_REQUEST["cid"]);
+                       $cidt = db_escape_string($_REQUEST["cidt"]);
+                       $cidb = db_escape_string($_REQUEST["cidb"]);
                        //$amount = (int) $_REQUEST["amount"];
                        //$unread_only = db_escape_string($_REQUEST["unread_only"]);
                        //if (!$amount) $amount = 50;
 
-                       $amount = 200;
+                       $amount = 100;
                        $unread_only = true;
 
                        print "<rpc-reply>";
                                                $unread_qpart = "unread = true AND ";
                                        }
 
-                                       if ($cid) {
-                                               $cid_qpart =  "id > $cid AND ";
+                                       if ($cidt && $cidb) {
+                                               $cid_qpart =  "(id > $cidt OR id < $cidb) AND ";
                                        }
 
+                                       if (DB_TYPE == "pgsql") {
+                                               $date_qpart = "updated >= NOW() - INTERVAL '1 month' AND";
+                                       } else {
+                                               $date_qpart = "updated >= DATE_SUB(NOW(), INTERVAL 1 MONTH) AND";
+                                       }                       
+
                                        $result = db_query($link,
                                                "SELECT DISTINCT id,title,guid,link,
                                                                feed_id,content,updated,unread,marked FROM
                                                        ttrss_user_entries,ttrss_entries
-                                                       WHERE $unread_qpart $cid_qpart
+                                                       WHERE $unread_qpart $cid_qpart $date_qpart
                                                        ref_id = id AND owner_uid = ".$_SESSION["uid"]."
                                                        ORDER BY updated DESC LIMIT $limit OFFSET $skip");
        
index 0182e8e5bc1e7c6049adb17fce4ba6e5c8c7a3da..96f0b347255a910e3c6d760620ca6b030839bd2b 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -26,7 +26,6 @@ var store = false;
 var localServer = false;
 var db = false;
 var download_progress_last = 0;
-var offline_dl_max_id = 0;
 
 function activeFeedIsCat() {
        return _active_feed_is_cat;
@@ -1584,7 +1583,7 @@ function offline_download_parse(stage, transport) {
                                                [id, title, has_icon]);
                                }
                
-                               window.setTimeout("update_offline_data("+(stage+1)+")", 30*1000);
+                               window.setTimeout("update_offline_data("+(stage+1)+")", 60*1000);
                        } else {
 
                                var articles = transport.responseXML.getElementsByTagName("article");
@@ -1614,6 +1613,12 @@ function offline_download_parse(stage, transport) {
                                        window.setTimeout("update_offline_data("+(stage+1)+")", 60*1000);
                                } else {
                                        window.setTimeout("update_offline_data(0)", 1800*1000);
+
+                                       var date = new Date();
+                                       var ts = Math.round(date.getTime() / 1000);
+
+                                       db.execute("DELETE FROM articles WHERE added < ? - 2592000", [ts]);
+
                                }
                        }
 
@@ -1634,15 +1639,13 @@ function update_offline_data(stage) {
 
                var query = "backend.php?op=rpc&subop=download&stage=" + stage;
 
-               if (stage == 0) {
-                       var rs = db.execute("SELECT MAX(id) FROM articles");
-                       if (rs.isValidRow() && rs.field(0)) {
-                               offline_dl_max_id = rs.field(0);
-                       }
-               }
+               var rs = db.execute("SELECT MAX(id), MIN(id) FROM articles");
+               if (rs.isValidRow() && rs.field(0)) {
+                       var offline_dl_max_id = rs.field(0);
+                       var offline_dl_min_id = rs.field(1);
 
-               if (offline_dl_max_id) {
-                       query = query + "&cid=" + offline_dl_max_id;
+                       query = query + "&cidt=" + offline_dl_max_id;
+                       query = query + "&cidb=" + offline_dl_min_id;
                }
 
                new Ajax.Request(query, {