implement random precaching of unread feeds on timer

master
Andrew Dolgov 13 years ago
parent 29465278c5
commit 452e75cc94

@ -297,6 +297,38 @@ dojo.declare("fox.FeedTree", dijit.Tree, {
});
},
getVisibleUnreadFeeds: function() {
var items = this.model.store._arrayOfAllItems;
var rv = [];
for (var i = 0; i < items.length; i++) {
var id = String(items[i].id);
var box = this._itemNodesMap[id];
if (box) {
var row = box[0].rowNode;
var cat = false;
try {
cat = box[0].rowNode.parentNode.parentNode;
} catch (e) { }
if (row) {
if (Element.visible(row) && (!cat || Element.visible(cat))) {
var feed_id = String(items[i].bare_id);
var is_cat = !id.match('FEED:');
var unread = this.model.getFeedUnread(feed_id, is_cat);
if (unread > 0)
rv.push([feed_id, is_cat]);
}
}
}
}
return rv;
},
getNextFeed: function (feed, is_cat) {
if (is_cat) {
treeItem = this.model.store._itemsByIdentity['CAT:' + feed];

@ -202,6 +202,7 @@ function feedlist_init() {
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
setTimeout("timeout()", 5000);
setTimeout("precache_headlines_idle()", 3000);
} catch (e) {
exception_error("feedlist/init", e);

@ -10,6 +10,7 @@ var last_requested_article = false;
var catchup_id_batch = [];
var catchup_timeout_id = false;
var feed_precache_timeout_id = false;
var precache_idle_timeout_id = false;
var cids_requested = [];
@ -2108,6 +2109,29 @@ function render_local_headlines(feed, is_cat, obj) {
}
}
function precache_headlines_idle() {
try {
if (!feed_precache_timeout_id) {
var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
var uncached = [];
feeds.each(function(item) {
if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
uncached.push(item);
});
if (uncached.length > 0) {
var rf = uncached[Math.floor(Math.random()*uncached.length)];
viewfeed(rf[0], '', rf[1], 0, true);
}
}
precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 5000);
} catch (e) {
exception_error("precache_headlines_idle", e);
}
}
function precache_headlines() {
try {

Loading…
Cancel
Save