1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Fixed problem with polling

This commit is contained in:
Jeremy Ruston 2012-11-19 13:59:32 +00:00
parent 6463f972e0
commit b8fcc9f0c0

View File

@ -61,12 +61,8 @@ TiddlyWebSyncer.prototype.addConnection = function(connection) {
// Get the login status // Get the login status
this.getStatus(function (err,isLoggedIn,json) { this.getStatus(function (err,isLoggedIn,json) {
if(isLoggedIn) { if(isLoggedIn) {
// Do a sync now // Do a sync
self.syncFromServer(); self.syncFromServer();
// And every so often
window.setInterval(function() {
self.syncFromServer.call(self);
},TiddlyWebSyncer.pollTimerInterval)
} }
}); });
return ""; // We only support a single connection return ""; // We only support a single connection
@ -269,22 +265,28 @@ console.log("error in syncFromServer",err);
return; return;
} }
// Store the skinny versions of these tiddlers // Store the skinny versions of these tiddlers
var json = JSON.parse(data); var json = JSON.parse(data),
wasAnyTiddlerStored = false;
for(var t=0; t<json.length; t++) { for(var t=0; t<json.length; t++) {
var tiddlerFields = json[t]; var tiddlerFields = json[t];
// Check if the tiddler is already present and not skinny // Check if the tiddler is already present and not skinny
var tiddler = self.wiki.getTiddler(tiddlerFields.title), var tiddler = self.wiki.getTiddler(tiddlerFields.title),
isFat = tiddler && tiddler.fields.text !== undefined; isFat = tiddler && tiddler.fields.text !== undefined;
// Store the tiddler // Store the tiddler
var wasStored = self.storeTiddler(tiddlerFields,tiddlerFields.revision); var wasTiddlerStored = self.storeTiddler(tiddlerFields,tiddlerFields.revision);
// Load the body of the tiddler if it was already fat, and we actually stored something // Load the body of the tiddler if it was already fat, and we actually stored something
if(isFat && wasStored) { if(isFat && wasTiddlerStored) {
self.enqueueSyncTask({ self.enqueueSyncTask({
type: "load", type: "load",
title: tiddlerFields.title title: tiddlerFields.title
}); });
} }
wasAnyTiddlerStored = wasTiddlerStored || wasAnyTiddlerStored;
} }
// Trigger another sync
window.setTimeout(function() {
self.syncFromServer.call(self);
},TiddlyWebSyncer.pollTimerInterval);
} }
}); });
}; };