add experimental headline caching

master
Andrew Dolgov 17 years ago
parent 1a9b5b84a7
commit e19c1824e9

@ -231,6 +231,10 @@
print "<headlines-count value=\"$headlines_count\"/>";
$headlines_unread = getFeedUnread($link, $feed);
print "<headlines-unread value=\"$headlines_unread\"/>";
if ($_GET["debug"]) $timing_info = print_checkpoint("10", $timing_info);
if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE')) {

@ -136,10 +136,6 @@ function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) {
query = query + "&omode=flc";
}
if (!page_offset) {
notify_progress("Loading, please wait...", true);
}
var container = document.getElementById("headlinesInnerContainer");
if (container && page_offset == 0 && !isCdmMode()) {
@ -147,10 +143,63 @@ function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) {
queue: { position:'end', scope: 'FEEDL-' + feed, limit: 1 } } );
}
new Ajax.Request(query, {
onComplete: function(transport) {
headlines_callback2(transport, feed, is_cat, page_offset);
} });
var unread_ctr = document.getElementById("FEEDU-" + feed);
var cache_check = false;
if (unread_ctr && !page_offset) {
unread_ctr = unread_ctr.innerHTML;
cache_check = cache_check_param("F:" + feed, unread_ctr);
debug("headline cache check: " + cache_check);
}
if (cache_check) {
var f = document.getElementById("headlines-frame");
clean_feed_selections();
setActiveFeedId(feed);
if (is_cat != undefined) {
active_feed_is_cat = is_cat;
}
if (!is_cat) {
var feedr = document.getElementById("FEEDR-" + feed);
if (feedr && !feedr.className.match("Selected")) {
feedr.className = feedr.className + "Selected";
}
}
f.innerHTML = cache_find("F:" + feed);
var query = "backend.php?op=rpc&subop=getAllCounters";
if (tagsAreDisplayed()) {
query = query + "&omode=tl";
} else {
query = query + "&omode=flc";
}
new Ajax.Request(query, {
onComplete: function(transport) {
try {
all_counters_callback2(transport);
} catch (e) {
exception_error("viewfeed/getcounters", e);
}
} });
} else {
if (!page_offset) {
notify_progress("Loading, please wait...", true);
}
new Ajax.Request(query, {
onComplete: function(transport) {
headlines_callback2(transport, feed, is_cat, page_offset);
} });
}
} catch (e) {
exception_error("viewfeed", e);

@ -45,11 +45,8 @@ function catchup_callback2(transport, callback) {
}
}
function headlines_callback2(transport, active_feed_id, is_cat, feed_cur_page) {
function clean_feed_selections() {
try {
debug("headlines_callback2 [page=" + feed_cur_page + "]");
var feeds = document.getElementById("feedList").getElementsByTagName("LI");
for (var i = 0; i < feeds.length; i++) {
@ -57,6 +54,17 @@ function headlines_callback2(transport, active_feed_id, is_cat, feed_cur_page) {
feeds[i].className = feeds[i].className.replace("Selected", "");
}
}
} catch (e) {
exception_error("clean_feed_selections", e);
}
}
function headlines_callback2(transport, active_feed_id, is_cat, feed_cur_page) {
try {
debug("headlines_callback2 [page=" + feed_cur_page + "]");
clean_feed_selections();
setActiveFeedId(active_feed_id);
@ -82,8 +90,10 @@ function headlines_callback2(transport, active_feed_id, is_cat, feed_cur_page) {
if (transport.responseXML) {
var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
var headlines_count_obj = transport.responseXML.getElementsByTagName("headlines-count")[0];
var headlines_unread_obj = transport.responseXML.getElementsByTagName("headlines-unread")[0];
var headlines_count = headlines_count_obj.getAttribute("value");
var headlines_unread = headlines_unread_obj.getAttribute("value");
if (headlines_count == 0) _infscroll_disable = 1;
@ -94,6 +104,10 @@ function headlines_callback2(transport, active_feed_id, is_cat, feed_cur_page) {
if (feed_cur_page == 0) {
if (headlines) {
f.innerHTML = headlines.firstChild.nodeValue;
cache_inject("F:" + active_feed_id,
headlines.firstChild.nodeValue, headlines_unread);
} else {
debug("headlines_callback: returned no data");
f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
@ -1181,19 +1195,20 @@ function cdmWatchdog() {
}
function cache_inject(id, article) {
if (!cache_check(id)) {
debug("cache_article: miss: " + id);
function cache_inject(id, article, param) {
if (!cache_check(id, param)) {
debug("cache_article: miss: " + id + " [p=" + param + "]");
var cache_obj = new Array();
cache_obj["id"] = id;
cache_obj["data"] = article;
cache_obj["param"] = param;
article_cache.push(cache_obj);
} else {
debug("cache_article: hit: " + id);
debug("cache_article: hit: " + id + " [p=" + param + "]");
}
}
@ -1206,6 +1221,15 @@ function cache_find(id) {
return false;
}
function cache_get_param(id) {
for (var i = 0; i < article_cache.length; i++) {
if (article_cache[i]["id"] == id) {
return article_cache[i]["param"];
}
}
return false;
}
function cache_check(id) {
for (var i = 0; i < article_cache.length; i++) {
if (article_cache[i]["id"] == id) {
@ -1215,6 +1239,15 @@ function cache_check(id) {
return false;
}
function cache_check_param(id, param) {
for (var i = 0; i < article_cache.length; i++) {
if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
return true;
}
}
return false;
}
function cache_expire() {
while (article_cache.length > 20) {
article_cache.shift();

Loading…
Cancel
Save