use caching for unexpanded CDM

This commit is contained in:
Andrew Dolgov 2011-08-31 22:33:15 +04:00
parent 87085cc848
commit b1a4b0e98f
2 changed files with 46 additions and 27 deletions

View File

@ -786,7 +786,15 @@
// 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"]);
$ids = array_merge($ids, $cids);
$rv = array();
foreach ($ids as $id) {
$id = (int)$id;
$result = db_query($link, "SELECT content,
ttrss_feeds.site_url AS site_url FROM ttrss_user_entries, ttrss_feeds,
@ -801,12 +809,12 @@
$article_content = sanitize_rss($link, $line["content"],
false, false, $line['site_url']);
} else {
$article_content = '';
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;
}

View 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']);
});
}});
}