summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2009-02-04 23:30:05 +0300
committerAndrew Dolgov <[email protected]>2009-02-04 23:30:05 +0300
commit3e52ab08db639e8cffd1216ec02fc4b18dbdd373 (patch)
tree53c1136cbf9002291223cb437f922ab5aacab0f1
parent76d20f5fafbc793f7d29686c09c9516cd7546d6c (diff)
offline downloader: better detect when no more additional requests are needed
-rw-r--r--modules/backend-rpc.php2
-rw-r--r--offline.js19
2 files changed, 17 insertions, 4 deletions
diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php
index 033646c34..78ccd1fd6 100644
--- a/modules/backend-rpc.php
+++ b/modules/backend-rpc.php
@@ -555,6 +555,8 @@
$limit = 50;
$skip = $limit*($stage-1);
+ print "<limit value=\"$limit\"/>";
+
if ($amount > 0) $amount -= $skip;
if ($amount > 0) {
diff --git a/offline.js b/offline.js
index 05c190250..f50644b7a 100644
--- a/offline.js
+++ b/offline.js
@@ -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) {