offline downloader: better detect when no more additional requests are needed
This commit is contained in:
parent
76d20f5faf
commit
3e52ab08db
|
@ -555,6 +555,8 @@
|
||||||
$limit = 50;
|
$limit = 50;
|
||||||
$skip = $limit*($stage-1);
|
$skip = $limit*($stage-1);
|
||||||
|
|
||||||
|
print "<limit value=\"$limit\"/>";
|
||||||
|
|
||||||
if ($amount > 0) $amount -= $skip;
|
if ($amount > 0) $amount -= $skip;
|
||||||
|
|
||||||
if ($amount > 0) {
|
if ($amount > 0) {
|
||||||
|
|
19
offline.js
19
offline.js
|
@ -549,11 +549,19 @@ function offline_download_parse(stage, transport) {
|
||||||
[id, title, has_icon]);
|
[id, title, has_icon]);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.setTimeout("update_offline_data("+(stage+1)+")", 60*1000);
|
window.setTimeout("update_offline_data("+(stage+1)+")", 10*1000);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
var articles = transport.responseXML.getElementsByTagName("article");
|
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;
|
var articles_found = 0;
|
||||||
|
|
||||||
for (var i = 0; i < articles.length; i++) {
|
for (var i = 0; i < articles.length; i++) {
|
||||||
|
@ -576,10 +584,14 @@ function offline_download_parse(stage, transport) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (articles_found > 0) {
|
debug("downloaded articles: " + articles_found + " limit: " + limit);
|
||||||
window.setTimeout("update_offline_data("+(stage+1)+")", 60*1000);
|
|
||||||
|
if (articles_found >= limit) {
|
||||||
|
window.setTimeout("update_offline_data("+(stage+1)+")", 10*1000);
|
||||||
|
debug("update_offline_data: done " + stage);
|
||||||
} else {
|
} else {
|
||||||
window.setTimeout("update_offline_data(0)", 1800*1000);
|
window.setTimeout("update_offline_data(0)", 1800*1000);
|
||||||
|
debug("update_offline_data: finished");
|
||||||
|
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
var ts = Math.round(date.getTime() / 1000);
|
var ts = Math.round(date.getTime() / 1000);
|
||||||
|
@ -624,7 +636,6 @@ function update_offline_data(stage) {
|
||||||
new Ajax.Request(query, {
|
new Ajax.Request(query, {
|
||||||
onComplete: function(transport) {
|
onComplete: function(transport) {
|
||||||
offline_download_parse(stage, transport);
|
offline_download_parse(stage, transport);
|
||||||
debug("update_offline_data: done " + stage);
|
|
||||||
} });
|
} });
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue