From 997d9d7cad31d5fdd3d054b95bd952a6f0367be9 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 20 May 2008 16:59:42 +0100 Subject: view: request counters in background, request_counters(): add client rate limit --- backend.php | 4 ++-- feedlist.js | 24 +++++++++++++++++++++++- viewfeed.js | 9 +++++---- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/backend.php b/backend.php index ba7cbdb0b..94a63dae1 100644 --- a/backend.php +++ b/backend.php @@ -210,11 +210,11 @@ } } - if ($mode != "prefetch_old") { +/* if ($mode != "prefetch_old") { print ""; getAllCounters($link, $omode); print ""; - } + } */ print ""; break; // view diff --git a/feedlist.js b/feedlist.js index df30a6107..b4a0e8832 100644 --- a/feedlist.js +++ b/feedlist.js @@ -496,7 +496,7 @@ function mouse_up_handler(e) { } } -function request_counters() { +function request_counters_real() { try { var query = "backend.php?op=rpc&subop=getAllCounters"; @@ -516,6 +516,28 @@ function request_counters() { } } }); + } catch (e) { + exception_error("request_counters_real", e); + } +} + +var counters_last_request = 0; + +function request_counters() { + + try { + + var date = new Date(); + var timestamp = Math.round(date.getTime() / 1000); + + if (timestamp - counters_last_request > 10) { + debug("scheduling request of counters..."); + window.setTimeout("request_counters_real()", 100); + counters_last_request = timestamp; + } else { + debug("request_counters: rate limit reached: " + (timestamp - counters_last_request)); + } + } catch (e) { exception_error("request_counters", e); } diff --git a/viewfeed.js b/viewfeed.js index 16f96216a..bd548ced9 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -325,7 +325,7 @@ function article_callback2(transport, id, feed_id) { active_real_feed_id = feed_id; active_post_id = id; - //showArticleInHeadlines(id); + showArticleInHeadlines(id); var reply = transport.responseXML.firstChild.firstChild; @@ -367,7 +367,8 @@ function article_callback2(transport, id, feed_id) { debug("parsing piggybacked counters: " + counters); parse_counters(counters, false); } else { - debug("counters container not found in reply"); + debug("counters container not found in reply, requesting..."); + request_counters(); } } @@ -426,8 +427,6 @@ function view(id, feed_id, skip_history) { var crow = document.getElementById("RROW-" + id); var article_is_unread = crow.className.match("Unread"); - showArticleInHeadlines(id); - if (!cached_article) { notify_progress("Loading, please wait..."); @@ -442,6 +441,8 @@ function view(id, feed_id, skip_history) { query = query + "&mode=prefetch_old"; render_article(cached_article); + showArticleInHeadlines(id); + } cache_expire(); -- cgit v1.2.3