diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index 3042703ca..dd6ea2694 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -516,12 +516,13 @@ 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 ""; @@ -564,15 +565,21 @@ $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"); diff --git a/tt-rss.js b/tt-rss.js index 0182e8e5b..96f0b3472 100644 --- 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, {