]> git.wh0rd.org Git - tt-rss.git/commitdiff
use caching for unexpanded CDM
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 31 Aug 2011 18:33:15 +0000 (22:33 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 31 Aug 2011 18:33:15 +0000 (22:33 +0400)
modules/backend-rpc.php
viewfeed.js

index dff12aa5a3ee5e6dfff67886fd264aa52da57a33..6c0abf7153cd18e64bebea17ae2075e8af26437c 100644 (file)
 
                // TODO: unify with digest-get-contents?
                if ($subop == "cdmGetArticle") {
-                       $id = db_escape_string($_REQUEST["id"]);
+                       $ids = array(db_escape_string($_REQUEST["id"]));
+                       $cids = explode(",", $_REQUEST["cids"]);
 
-                       $result = db_query($link, "SELECT content,
-                               ttrss_feeds.site_url AS site_url FROM ttrss_user_entries, ttrss_feeds,
-                               ttrss_entries
-                               WHERE feed_id = ttrss_feeds.id AND ref_id = '$id' AND
-                               ttrss_entries.id = ref_id AND
-                               ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
+                       $ids = array_merge($ids, $cids);
 
-                       if (db_num_rows($result) != 0) {
-                               $line = db_fetch_assoc($result);
+                       $rv = array();
 
-                               $article_content = sanitize_rss($link, $line["content"],
-                                       false, false, $line['site_url']);
+                       foreach ($ids as $id) {
+                               $id = (int)$id;
 
-                       } else {
-                               $article_content = '';
+                               $result = db_query($link, "SELECT content,
+                                       ttrss_feeds.site_url AS site_url FROM ttrss_user_entries, ttrss_feeds,
+                                       ttrss_entries
+                                       WHERE feed_id = ttrss_feeds.id AND ref_id = '$id' AND
+                                       ttrss_entries.id = ref_id AND
+                                       ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
+
+                               if (db_num_rows($result) != 0) {
+                                       $line = db_fetch_assoc($result);
+
+                                       $article_content = sanitize_rss($link, $line["content"],
+                                               false, false, $line['site_url']);
+
+                                       array_push($rv,
+                                               array("id" => $id, "content" => $article_content));
+                               }
                        }
 
-                       print json_encode(array("article" =>
-                               array("id" => $id, "content" => $article_content)));
+                       print json_encode($rv);
 
                        return;
                }
index 368a1ed4c1ac993871fdc699ea0449edbe4afe87..1718c810af6cdbed18070275690824e8d96ae655 100644 (file)
@@ -1235,28 +1235,39 @@ function cdmExpandArticle(id) {
 
                                var query = "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id);
 
-                               //console.log(query);
+                               var neighbor_ids = getRelativePostIds(id);
+
+                               /* only request uncached articles */
+                               var cids_to_request = [];
+
+                               for (var i = 0; i < neighbor_ids.length; i++) {
+                                       if (cids_requested.indexOf(neighbor_ids[i]) == -1)
+                                               if ($("CWRAP-" + neighbor_ids[i]).innerHTML == "") {
+                                                       cids_to_request.push(neighbor_ids[i]);
+                                                       cids_requested.push(neighbor_ids[i]);
+                                               }
+                               }
+
+                               console.log("additional ids: " + cids_to_request.toString());
+
+                               query = query + "&cids=" + cids_to_request.toString();
+
+                               console.log(query);
 
                                new Ajax.Request("backend.php", {
                                        parameters: query,
                                        onComplete: function(transport) {
+
                                                $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
 
                                                handle_rpc_json(transport);
 
                                                var reply = JSON.parse(transport.responseText);
 
-                                               if (reply) {
-                                                       var article = reply['article']['content'];
-                                                       var recv_id = reply['article']['id'];
-
-                                                       if (recv_id == id)
-                                                               $("CWRAP-" + id).innerHTML = article;
-
-                                               } else {
-                                                       $("CWRAP-" + id).innerHTML = __("Unable to load article.");
-
-                                               }
+                                               reply.each(function(article) {
+                                                       $("CWRAP-" + article['id']).innerHTML = article['content']
+                                                       cids_requested.remove(article['id']);
+                                               });
                                }});
 
                        }