]> git.wh0rd.org - tt-rss.git/commitdiff
improve headline caching, update cache after toggleMark/togglePub()
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 31 Aug 2011 13:56:41 +0000 (17:56 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 31 Aug 2011 14:10:47 +0000 (18:10 +0400)
feedlist.js
viewfeed.js

index fc3bcd9c73685d6362f8b333f99b23af1ebe9360..27cd8295a37ac0ebf708cc97d677964dd9a12d26 100644 (file)
@@ -1,11 +1,9 @@
-//var _feed_cur_page = 0;
 var _infscroll_disable = 0;
 var _infscroll_request_sent = 0;
 var _search_query = false;
 
 var counter_timeout_id = false;
 
-var resize_enabled = false;
 var counters_last_request = 0;
 
 function viewCategory(cat) {
index b040dc1555d6b068fb9e49e24eeb9c5b355d2950..8d4aeefd3ab7afca132d52eb9bcd1b25f926a6e7 100644 (file)
@@ -1,6 +1,4 @@
 var active_post_id = false;
-var last_article_view = false;
-var active_real_feed_id = false;
 
 var article_cache = new Array();
 
@@ -142,6 +140,10 @@ function headlines_callback2(transport, offset, background) {
                                console.log("no cached articles received");
                        }
 
+                       // do not precache stuff after fresh feed
+                       if (feed_id != -3)
+                               precache_headlines();
+
                        if (counters)
                                parse_counters(counters);
                        else
@@ -153,7 +155,6 @@ function headlines_callback2(transport, offset, background) {
                                        __('Could not update headlines (invalid object received)') + "</div>");
                }
 
-               //_feed_cur_page = feed_cur_page;
                _infscroll_request_sent = 0;
 
                notify("");
@@ -270,9 +271,6 @@ function article_callback2(transport, id) {
                                        __('Could not display article (invalid data received)') + "</div>");
                }
 
-               var date = new Date();
-               last_article_view = date.getTime() / 1000;
-
                request_counters();
 
                notify("");
@@ -317,23 +315,7 @@ function view(id) {
                active_post_id = id;
                showArticleInHeadlines(id);
 
-               if (!feed_precache_timeout_id) {
-                       feed_precache_timeout_id = window.setTimeout(function() {
-                               var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
-                               var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
-
-                               if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
-                                       viewfeed(nuf, '', activeFeedIsCat(), 0, true);
-
-                               if (nf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
-                                       viewfeed(nf[0], '', nf[1], 0, true);
-
-                               window.setTimeout(function() {
-                                       feed_precache_timeout_id = false;
-                                       }, 3000);
-
-                       }, 1000);
-               }
+               precache_headlines();
 
                if (!cached_article) {
 
@@ -404,6 +386,8 @@ function toggleMark(id, client_only) {
                        query = query + "&mark=0";
                }
 
+               cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
+
                if (!client_only) {
                        new Ajax.Request("backend.php", {
                                parameters: query,
@@ -443,6 +427,8 @@ function togglePub(id, client_only, no_effects, note) {
                        query = query + "&pub=0";
                }
 
+               cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
+
                if (!client_only) {
                        new Ajax.Request("backend.php", {
                                parameters: query,
@@ -2082,9 +2068,11 @@ function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
                        JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
        } else {
                try {
-                       obj =   JSON.parse(cache_get("feed:" + feed + ":" + is_cat));
+                       obj =   cache_get("feed:" + feed + ":" + is_cat);
 
                        if (obj) {
+                               obj = JSON.parse(obj);
+
                                if (toolbar_obj) obj.toolbar = toolbar_obj;
                                if (content_obj) obj.content = content_obj;
 
@@ -2112,7 +2100,36 @@ function render_local_headlines(feed, is_cat, obj) {
                selectArticles('none');
                setActiveFeedId(feed, is_cat);
                initHeadlinesMenu();
+
+               precache_headlines();
+
        } catch (e) {
                exception_error("render_local_headlines", e);
        }
 }
+
+function precache_headlines() {
+       try {
+
+               if (!feed_precache_timeout_id) {
+                       feed_precache_timeout_id = window.setTimeout(function() {
+                               var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
+                               var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
+
+                               if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
+                                       viewfeed(nuf, '', activeFeedIsCat(), 0, true);
+
+                               if (nf != nuf && nf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
+                                       viewfeed(nf[0], '', nf[1], 0, true);
+
+                               window.setTimeout(function() {
+                                       feed_precache_timeout_id = false;
+                                       }, 3000);
+
+                       }, 1000);
+               }
+
+       } catch (e) {
+               exception_error("precache_headlines", e);
+       }
+}