]> git.wh0rd.org - tt-rss.git/commitdiff
add experimental headline caching
authorAndrew Dolgov <fox@madoka.spb.ru>
Wed, 21 Nov 2007 08:23:34 +0000 (09:23 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Wed, 21 Nov 2007 08:23:34 +0000 (09:23 +0100)
backend.php
feedlist.js
viewfeed.js

index 482b46feb719d4bbb5fd999897d6216f5a0528af..826a1ed92fd41fec1e09d7b7712688c53aabfda2 100644 (file)
 
                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')) {
index 03dea359a7fa3aac6a13e6d5ad8dde4a9c912462..46bf103e1a578a62c8320c9b808b53de60237f91 100644 (file)
@@ -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);
index be790020444bd5f4e5f5e081a311f3203fbf34aa..492f1f0927459559b6b5f0c126eb8a4f42d695e1 100644 (file)
@@ -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,9 +90,11 @@ 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;
        
                        var counters = transport.responseXML.getElementsByTagName("counters")[0];
@@ -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();