From 1e0d019610acd960b8c70c0b85b7bb1a25096a8f Mon Sep 17 00:00:00 2001 From: Jermolene Date: Mon, 18 Apr 2016 14:50:13 +0100 Subject: [PATCH] Don't repeatedly lazy load the same tiddler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we don’t get a “text” field back the first time we shouldn’t keep asking for it. --- core/modules/syncer.js | 44 ++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/core/modules/syncer.js b/core/modules/syncer.js index 223998e1c..15934ca9d 100644 --- a/core/modules/syncer.js +++ b/core/modules/syncer.js @@ -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;