Mercurial > snowl
changeset 283:ae23e6f323db
refresh twitter every three minutes
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Mon, 01 Sep 2008 20:15:33 -0700 |
parents | 76ee747a1dba |
children | e9a79cea3deb |
files | modules/opml.js modules/service.js modules/source.js modules/twitter.js |
diffstat | 4 files changed, 16 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/modules/opml.js Mon Sep 01 19:01:56 2008 -0700 +++ b/modules/opml.js Mon Sep 01 20:15:33 2008 -0700 @@ -39,7 +39,7 @@ const Cr = Components.results; const Cu = Components.utils; -Cu.import("resource://snowl/modules/source.js"); +Cu.import("resource://snowl/modules/service.js"); let EXPORTED_SYMBOLS = ["SnowlOPML"]; @@ -100,7 +100,7 @@ root.appendChild(body); // Populate the <body> element with <outline> elements. - let sources = SnowlSource.getAll(); + let sources = SnowlService.getSources(); for each (let source in sources) { let outline = doc.createElement("outline"); // XXX Should we specify the |type| attribute, and should we specify
--- a/modules/service.js Mon Sep 01 19:01:56 2008 -0700 +++ b/modules/service.js Mon Sep 01 20:15:33 2008 -0700 @@ -57,9 +57,6 @@ const SNOWL_HANDLER_URI = "chrome://snowl/content/subscribe.xul?feed=%s"; const SNOWL_HANDLER_TITLE = "Snowl"; -// How often to refresh sources, in milliseconds. -const REFRESH_INTERVAL = 60 * 60 * 1000; // 60 minutes - // How often to check if sources need refreshing, in milliseconds. const REFRESH_CHECK_INTERVAL = 60 * 1000; // 60 seconds @@ -226,8 +223,8 @@ let constructor = eval(row.type); if (!constructor) { - this._log.error("no constructor for type " + row.type); - continue; + this._log.warn("constructor " + row.type + " not defined; using SnowlSource"); + constructor = SnowlSource; } sources.push(new constructor(row.id, @@ -255,12 +252,10 @@ let allSources = this.getSources(); let now = new Date(); let staleSources = []; - for each (let source in allSources) -{ -//this._log.info("checking source: " + source.id); - if (now - source.lastRefreshed > REFRESH_INTERVAL) -{ -this._log.info("source: " + source.id + " is stale"); + for each (let source in allSources) { + //this._log.info(source.name + " last refreshed " + source.lastRefreshed + ", " + (now - source.lastRefreshed)/1000 + "s ago; interval is " + source.refreshInterval/1000 + "s"); + if (now - source.lastRefreshed > source.refreshInterval) { + this._log.info("source: " + source.id + " is stale; refreshing"); staleSources.push(source); } }
--- a/modules/source.js Mon Sep 01 19:01:56 2008 -0700 +++ b/modules/source.js Mon Sep 01 20:15:33 2008 -0700 @@ -87,40 +87,7 @@ return null; } -SnowlSource.__defineGetter__("_getAllStatement", - function() { - let statement = SnowlDatastore.createStatement( - "SELECT id, name, machineURI, humanURI, lastRefreshed, importance " + - "FROM sources ORDER BY name" - ); - this.__defineGetter__("_getAllStatement", function() { return statement }); - return this._getAllStatement; - } -); - -/** - * Get all sources. - */ -SnowlSource.getAll = function() { - let sources = []; - - try { - while (this._getAllStatement.step()) - sources.push(new SnowlSource(this._getAllStatement.row.id, - this._getAllStatement.row.name, - URI.get(this._getAllStatement.row.machineURI), - URI.get(this._getAllStatement.row.humanURI), - new Date(this._getAllStatement.row.lastRefreshed), - this._getAllStatement.row.importance)); - } - finally { - this._getAllStatement.reset(); - } - - return sources; -} - - // Favicon Service +// Favicon Service SnowlSource.__defineGetter__("faviconSvc", function() { let faviconSvc = Cc["@mozilla.org/browser/favicon-service;1"]. @@ -132,6 +99,9 @@ ); SnowlSource.prototype = { + // How often to refresh sources, in milliseconds. + refreshInterval: 1000 * 60 * 30, // 30 minutes + id: null, name: null,
--- a/modules/twitter.js Mon Sep 01 19:01:56 2008 -0700 +++ b/modules/twitter.js Mon Sep 01 20:15:33 2008 -0700 @@ -65,7 +65,7 @@ // XXX Should this be simply http://twitter.com ? const HUMAN_URI = URI.get("http://twitter.com/home"); -function SnowlTwitter(aID, aLastRefreshed, aImportance) { +function SnowlTwitter(aID, aName, aMachineURI, aHumanURI, aLastRefreshed, aImportance) { // XXX Should we append the username to the NAME const to enable users // to subscribe to multiple Twitter accounts? @@ -74,6 +74,9 @@ } SnowlTwitter.prototype = { + // How often to refresh sources, in milliseconds. + refreshInterval: 1000 * 60 * 3, // 30 minutes + constructor: SnowlTwitter, __proto__: SnowlSource.prototype,