1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 10:29:54 +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] = {
revision: tiddler.fields.revision,
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)
*/
@ -128,7 +143,8 @@ Syncer.prototype.storeTiddler = function(tiddlerFields) {
this.tiddlerInfo[tiddlerFields.title] = {
revision: tiddlerFields.revision,
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
*/
Syncer.prototype.handleLazyLoadEvent = function(title) {
// Queue up a sync task to load this tiddler
this.enqueueSyncTask({
type: "load",
title: title
});
// Don't lazy load the same tiddler twice
var info = this.tiddlerInfo[title];
if(!info || !info.hasBeenLazyLoaded) {
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.lastModificationTime = now;
// Fill in some tiddlerInfo if the tiddler is one we haven't seen before
if(!$tw.utils.hop(this.tiddlerInfo,task.title)) {
this.tiddlerInfo[task.title] = {
revision: null,
adaptorInfo: {},
changeCount: -1
};
}
this.createTiddlerInfo(task.title);
// 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) {
return;