commit fb0202fef990625b16ba92420ad81b3e59e2d860
parent 1e2a6f5473c5eac5136eb7f713d81f30db2485cd
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 22 Feb 2009 09:56:11 +0000
Add server-based auto-sync throttling to client
Diffstat:
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/chrome/content/zotero/xpcom/sync.js b/chrome/content/zotero/xpcom/sync.js
@@ -588,7 +588,6 @@ Zotero.Sync.Runner.IdleListener = {
_backObserver: {
observe: function (subject, topic, data) {
if (topic != 'back') {
- Zotero.debug('back observer bailing on topic ' + topic);
return;
}
@@ -599,7 +598,7 @@ Zotero.Sync.Runner.IdleListener = {
return;
}
Zotero.debug("Beginning return-from-idle sync");
- Zotero.Sync.Runner.sync();
+ Zotero.Sync.Runner.sync(true);
}
},
@@ -628,6 +627,11 @@ Zotero.Sync.Server = new function () {
this.logout = logout;
this.__defineGetter__('enabled', function () {
+ if (_throttleTimeout && new Date() < _throttleTimeout) {
+ Zotero.debug("Auto-syncing is disabled until " + Zotero.Date.dateToSQL(_throttleTimeout) + " -- skipping sync");
+ return false;
+ }
+
// Set auto-sync expiry
var expiry = new Date("March 15, 2009 00:00:00");
if (new Date() > expiry) {
@@ -739,7 +743,7 @@ Zotero.Sync.Server = new function () {
var _syncInProgress;
var _sessionID;
var _sessionLock;
-
+ var _throttleTimeout;
function login(callback, callbackCallback) {
var url = _serverURL + "login";
@@ -1321,6 +1325,24 @@ Zotero.Sync.Server = new function () {
Zotero.debug(xmlhttp.responseText);
_error('Invalid response from server', xmlhttp.responseText);
}
+
+ // Temporarily disable auto-sync if instructed by server
+ if (xmlhttp.responseXML.firstChild.firstChild.localName == 'throttle') {
+ Zotero.debug(xmlhttp.responseText);
+ var delay = xmlhttp.responseXML.firstChild.firstChild.getAttribute('delay');
+ var time = new Date();
+ time = time.getTime() + (delay * 1000);
+ time = new Date(time);
+ _throttleTimeout = time;
+ if (delay < 86400000) {
+ var timeStr = time.toLocaleTimeString();
+ }
+ else {
+ var timeStr = time.toLocaleString();
+ }
+ // TODO: localize
+ _error("Auto-syncing disabled until " + timeStr);
+ }
}