use caching for unexpanded CDM
This commit is contained in:
parent
87085cc848
commit
b1a4b0e98f
2 changed files with 46 additions and 27 deletions
|
@ -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;
|
||||
}
|
||||
|
|
35
viewfeed.js
35
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']);
|
||||
});
|
||||
}});
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue