digest: add rate limit for headline requests when catching up; control OOE responses with seq numbers
This commit is contained in:
parent
eb4f33ec02
commit
e4c530dcc3
33
digest.js
33
digest.js
|
@ -3,7 +3,9 @@ var last_feeds = [];
|
||||||
var _active_feed_id = false;
|
var _active_feed_id = false;
|
||||||
var _active_feed_offset = false;
|
var _active_feed_offset = false;
|
||||||
var _update_timeout = false;
|
var _update_timeout = false;
|
||||||
|
var _view_update_timeout = false;
|
||||||
var _feedlist_expanded = false;
|
var _feedlist_expanded = false;
|
||||||
|
var _update_seq = 1;
|
||||||
|
|
||||||
function article_appear(article_id) {
|
function article_appear(article_id) {
|
||||||
try {
|
try {
|
||||||
|
@ -181,14 +183,23 @@ function remove_headline_entry(article_id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function view_update() {
|
||||||
|
try {
|
||||||
|
viewfeed(_active_feed_id, _active_feed_offset, false, true);
|
||||||
|
update();
|
||||||
|
} catch (e) {
|
||||||
|
exception_error("view_update", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function view(article_id, dismiss_only) {
|
function view(article_id, dismiss_only) {
|
||||||
try {
|
try {
|
||||||
remove_headline_entry(article_id);
|
remove_headline_entry(article_id);
|
||||||
|
|
||||||
catchup_article(article_id,
|
catchup_article(article_id,
|
||||||
function() {
|
function() {
|
||||||
viewfeed(_active_feed_id, _active_feed_offset, false, true);
|
window.clearTimeout(_view_update_timeout);
|
||||||
update();
|
_view_update_timeout = window.setTimeout("view_update()", 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
return dismiss_only != true;
|
return dismiss_only != true;
|
||||||
|
@ -210,8 +221,11 @@ function viewfeed(feed_id, offset, replace, no_effects) {
|
||||||
|
|
||||||
if (replace == undefined) replace = (offset == 0);
|
if (replace == undefined) replace = (offset == 0);
|
||||||
|
|
||||||
|
_update_seq = _update_seq + 1;
|
||||||
|
|
||||||
var query = "backend.php?op=rpc&subop=digest-update&feed_id=" +
|
var query = "backend.php?op=rpc&subop=digest-update&feed_id=" +
|
||||||
param_escape(feed_id) + "&offset=" + offset;
|
param_escape(feed_id) + "&offset=" + offset +
|
||||||
|
"&seq=" + _update_seq;
|
||||||
|
|
||||||
console.log(query);
|
console.log(query);
|
||||||
|
|
||||||
|
@ -222,6 +236,7 @@ function viewfeed(feed_id, offset, replace, no_effects) {
|
||||||
|
|
||||||
if ($('H-LOADING-IMG')) Element.show("H-LOADING-IMG");
|
if ($('H-LOADING-IMG')) Element.show("H-LOADING-IMG");
|
||||||
|
|
||||||
|
|
||||||
new Ajax.Request("backend.php", {
|
new Ajax.Request("backend.php", {
|
||||||
parameters: query,
|
parameters: query,
|
||||||
onComplete: function(transport) {
|
onComplete: function(transport) {
|
||||||
|
@ -465,6 +480,18 @@ function parse_headlines(transport, replace, no_effects) {
|
||||||
try {
|
try {
|
||||||
if (!transport.responseXML) return;
|
if (!transport.responseXML) return;
|
||||||
|
|
||||||
|
var seq = transport.responseXML.getElementsByTagName('seq')[0];
|
||||||
|
|
||||||
|
if (seq) {
|
||||||
|
seq = seq.firstChild.nodeValue;
|
||||||
|
if (seq != _update_seq) {
|
||||||
|
console.log("parse_headlines: wrong sequence received.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var headlines = transport.responseXML.getElementsByTagName('headlines')[0];
|
var headlines = transport.responseXML.getElementsByTagName('headlines')[0];
|
||||||
var headlines_title = transport.responseXML.getElementsByTagName('headlines-title')[0];
|
var headlines_title = transport.responseXML.getElementsByTagName('headlines-title')[0];
|
||||||
|
|
||||||
|
|
|
@ -1003,11 +1003,14 @@
|
||||||
if ($subop == "digest-update") {
|
if ($subop == "digest-update") {
|
||||||
$feed_id = db_escape_string($_REQUEST['feed_id']);
|
$feed_id = db_escape_string($_REQUEST['feed_id']);
|
||||||
$offset = db_escape_string($_REQUEST['offset']);
|
$offset = db_escape_string($_REQUEST['offset']);
|
||||||
|
$seq = db_escape_string($_REQUEST['seq']);
|
||||||
|
|
||||||
if (!$feed_id) $feed_id = -4;
|
if (!$feed_id) $feed_id = -4;
|
||||||
if (!$offset) $offset = 0;
|
if (!$offset) $offset = 0;
|
||||||
print "<rpc-reply>";
|
print "<rpc-reply>";
|
||||||
|
|
||||||
|
print "<seq>$seq</seq>";
|
||||||
|
|
||||||
$headlines = api_get_headlines($link, $feed_id, 10, $offset,
|
$headlines = api_get_headlines($link, $feed_id, 10, $offset,
|
||||||
'', ($feed_id == -4), true, false, "unread", "updated DESC");
|
'', ($feed_id == -4), true, false, "unread", "updated DESC");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue