From: Andrew Dolgov Date: Sun, 18 May 2008 08:51:07 +0000 (+0100) Subject: getNeighborIds: add scope, add automatic prefetch for articles under mouse X-Git-Tag: 1.2.23-final~64 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=aa0fa9df1ee81b1af80dd1c882ea171563f6b1e9;p=tt-rss.git getNeighborIds: add scope, add automatic prefetch for articles under mouse --- diff --git a/functions.js b/functions.js index 22d1ebb9..f716f350 100644 --- a/functions.js +++ b/functions.js @@ -1477,9 +1477,11 @@ function explainError(code) { } // this only searches loaded headlines list, not in CDM -function getRelativePostIds(id) { +function getRelativePostIds(id, limit) { - debug("getRelativePostIds: " + id); + if (!limit) limit = 3; + + debug("getRelativePostIds: " + id + " limit=" + limit); var ids = new Array(); var container = document.getElementById("headlinesList"); @@ -1491,13 +1493,23 @@ function getRelativePostIds(id) { var r_id = rows[i].id.replace("RROW-", ""); if (r_id == id) { - if (i > 0) ids.push(rows[i-1].id.replace("RROW-", "")); +/* if (i > 0) ids.push(rows[i-1].id.replace("RROW-", "")); if (i > 1) ids.push(rows[i-2].id.replace("RROW-", "")); if (i > 2) ids.push(rows[i-3].id.replace("RROW-", "")); if (i < rows.length-1) ids.push(rows[i+1].id.replace("RROW-", "")); if (i < rows.length-2) ids.push(rows[i+2].id.replace("RROW-", "")); - if (i < rows.length-3) ids.push(rows[i+3].id.replace("RROW-", "")); + if (i < rows.length-3) ids.push(rows[i+3].id.replace("RROW-", "")); */ + + for (var k = 1; k <= limit; k++) { + var nid = false; + + if (i > k-1) var nid = rows[i-k].id.replace("RROW-", ""); + if (nid) ids.push(nid); + + if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", ""); + if (nid) ids.push(nid); + } return ids; } diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index 1bff702a..2b3fe872 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -414,6 +414,21 @@ } + if ($subop == "getArticles") { + $ids = split(",", db_escape_string($_REQUEST["ids"])); + + print ""; + + foreach ($ids as $id) { + if ($id) { + outputArticleXML($link, $id, 0, false); + } + } + print ""; + + return; + } + print "Unknown method: $subop"; } ?> diff --git a/viewfeed.js b/viewfeed.js index a01c8a4a..b2a79b03 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -1604,9 +1604,66 @@ function cdmClicked(elem) { } } +function preload_article_callback(transport) { + try { + if (transport.responseXML) { + var articles = transport.responseXML.getElementsByTagName("article"); + + for (var i = 0; i < articles.length; i++) { + var id = articles[i].getAttribute("id"); + if (!cache_find(id)) { + cache_inject(id, articles[i].firstChild.nodeValue); + debug("preloaded article: " + id); + } + } + } + } catch (e) { + exception_error("preload_article_callback", e); + } +} + +function preloadArticleUnderPointer(id) { + try { + if (post_under_pointer == id && !cache_find(id)) { + + debug("trying to preload article " + id); + + var neighbor_ids = getRelativePostIds(id, 1); + + /* only request uncached articles */ + + var cids_to_request = Array(); + + for (var i = 0; i < neighbor_ids.length; i++) { + if (!cache_check(neighbor_ids[i])) { + cids_to_request.push(neighbor_ids[i]); + } + } + debug("additional ids: " + cids_to_request.toString()); + + cids_to_request.push(id); + + var query = "backend.php?op=rpc&subop=getArticles&ids=" + + cids_to_request.toString(); + new Ajax.Request(query, { + onComplete: function(transport) { + preload_article_callback(transport); + } }); + } + } catch (e) { + exception_error("preloadArticleUnderPointer", e); + } +} + function postMouseIn(id) { try { - post_under_pointer = id; + if (post_under_pointer != id) { + post_under_pointer = id; + if (!isCdmMode()) { + window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250); + } + } + } catch (e) { exception_error("postMouseIn", e); }