From b1a4b0e98fe6303e956bdb332960642ff6d1a24d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 31 Aug 2011 22:33:15 +0400 Subject: [PATCH] use caching for unexpanded CDM --- modules/backend-rpc.php | 38 +++++++++++++++++++++++--------------- viewfeed.js | 35 +++++++++++++++++++++++------------ 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index dff12aa5a..6c0abf715 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -786,27 +786,35 @@ // 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; } diff --git a/viewfeed.js b/viewfeed.js index 368a1ed4c..1718c810a 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -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']); + }); }}); }