1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 23:03:15 +00:00

Don't repeatedly lazy load the same tiddler

If we don’t get a “text” field back the first time we shouldn’t keep
asking for it.
This commit is contained in:
Jermolene 2016-04-18 14:50:13 +01:00
parent e6e346ea29
commit 1e0d019610

View File

@ -96,11 +96,26 @@ Syncer.prototype.readTiddlerInfo = function() {
self.tiddlerInfo[title] = { self.tiddlerInfo[title] = {
revision: tiddler.fields.revision, revision: tiddler.fields.revision,
adaptorInfo: self.syncadaptor && self.syncadaptor.getTiddlerInfo(tiddler), adaptorInfo: self.syncadaptor && self.syncadaptor.getTiddlerInfo(tiddler),
changeCount: self.wiki.getChangeCount(title) changeCount: self.wiki.getChangeCount(title),
hasBeenLazyLoaded: false
}; };
}); });
}; };
/*
Create an tiddlerInfo structure if it doesn't already exist
*/
Syncer.prototype.createTiddlerInfo = function(title) {
if(!$tw.utils.hop(this.tiddlerInfo,title)) {
this.tiddlerInfo[title] = {
revision: null,
adaptorInfo: {},
changeCount: -1,
hasBeenLazyLoaded: false
};
}
};
/* /*
Checks whether the wiki is dirty (ie the window shouldn't be closed) Checks whether the wiki is dirty (ie the window shouldn't be closed)
*/ */
@ -128,7 +143,8 @@ Syncer.prototype.storeTiddler = function(tiddlerFields) {
this.tiddlerInfo[tiddlerFields.title] = { this.tiddlerInfo[tiddlerFields.title] = {
revision: tiddlerFields.revision, revision: tiddlerFields.revision,
adaptorInfo: this.syncadaptor.getTiddlerInfo(tiddler), adaptorInfo: this.syncadaptor.getTiddlerInfo(tiddler),
changeCount: this.wiki.getChangeCount(tiddlerFields.title) changeCount: this.wiki.getChangeCount(tiddlerFields.title),
hasBeenLazyLoaded: true
}; };
}; };
@ -238,11 +254,17 @@ Syncer.prototype.syncToServer = function(changes) {
Lazily load a skinny tiddler if we can Lazily load a skinny tiddler if we can
*/ */
Syncer.prototype.handleLazyLoadEvent = function(title) { Syncer.prototype.handleLazyLoadEvent = function(title) {
// Queue up a sync task to load this tiddler // Don't lazy load the same tiddler twice
this.enqueueSyncTask({ var info = this.tiddlerInfo[title];
type: "load", if(!info || !info.hasBeenLazyLoaded) {
title: title this.createTiddlerInfo(title);
}); this.tiddlerInfo[title].hasBeenLazyLoaded = true;
// Queue up a sync task to load this tiddler
this.enqueueSyncTask({
type: "load",
title: title
});
}
}; };
/* /*
@ -324,13 +346,7 @@ Syncer.prototype.enqueueSyncTask = function(task) {
task.queueTime = now; task.queueTime = now;
task.lastModificationTime = now; task.lastModificationTime = now;
// Fill in some tiddlerInfo if the tiddler is one we haven't seen before // Fill in some tiddlerInfo if the tiddler is one we haven't seen before
if(!$tw.utils.hop(this.tiddlerInfo,task.title)) { this.createTiddlerInfo(task.title);
this.tiddlerInfo[task.title] = {
revision: null,
adaptorInfo: {},
changeCount: -1
};
}
// Bail if this is a save and the tiddler is already at the changeCount that the server has // Bail if this is a save and the tiddler is already at the changeCount that the server has
if(task.type === "save" && this.wiki.getChangeCount(task.title) <= this.tiddlerInfo[task.title].changeCount) { if(task.type === "save" && this.wiki.getChangeCount(task.title) <= this.tiddlerInfo[task.title].changeCount) {
return; return;