]> git.wh0rd.org - tt-rss.git/commitdiff
offline downloader: better detect when no more additional requests are needed
authorAndrew Dolgov <fox@bah.org.ru>
Wed, 4 Feb 2009 20:30:05 +0000 (23:30 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Wed, 4 Feb 2009 20:30:05 +0000 (23:30 +0300)
modules/backend-rpc.php
offline.js

index 033646c3481ac699c15adf976020fac0c1cb7152..78ccd1fd65f07e18908569a652980bb7efdde04f 100644 (file)
                                $limit = 50;
                                $skip = $limit*($stage-1);
 
+                               print "<limit value=\"$limit\"/>";
+
                                if ($amount > 0) $amount -= $skip;
 
                                if ($amount > 0) {
index 05c190250f951cac693f0bca62b97d666ad652a1..f50644b7a1386f88bb22ba165587a207d184d7a3 100644 (file)
@@ -549,11 +549,19 @@ function offline_download_parse(stage, transport) {
                                                [id, title, has_icon]);
                                }
                
-                               window.setTimeout("update_offline_data("+(stage+1)+")", 60*1000);
+                               window.setTimeout("update_offline_data("+(stage+1)+")", 10*1000);
                        } else {
 
                                var articles = transport.responseXML.getElementsByTagName("article");
 
+                               var limit = transport.responseXML.getElementsByTagName("limit")[0];
+
+                               if (limit) {
+                                       limit = limit.getAttribute("value");
+                               } else {
+                                       limit = 0;
+                               }
+
                                var articles_found = 0;
 
                                for (var i = 0; i < articles.length; i++) {                                     
@@ -576,10 +584,14 @@ function offline_download_parse(stage, transport) {
                                        }
                                }
 
-                               if (articles_found > 0) {
-                                       window.setTimeout("update_offline_data("+(stage+1)+")", 60*1000);
+                               debug("downloaded articles: " + articles_found + " limit: " + limit);
+
+                               if (articles_found >= limit) {
+                                       window.setTimeout("update_offline_data("+(stage+1)+")", 10*1000);
+                                       debug("update_offline_data: done " + stage);
                                } else {
                                        window.setTimeout("update_offline_data(0)", 1800*1000);
+                                       debug("update_offline_data: finished");
 
                                        var date = new Date();
                                        var ts = Math.round(date.getTime() / 1000);
@@ -624,7 +636,6 @@ function update_offline_data(stage) {
                new Ajax.Request(query, {
                        onComplete: function(transport) { 
                                offline_download_parse(stage, transport);                               
-                               debug("update_offline_data: done " + stage);
                        } });
 
        } catch (e) {