TiddlyWiki.org

Ticket #278 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

Story.prototype.saveTiddler sends too many notifications when extended fields are edited.

Reported by: UdoBorkowski Assigned to: JeremyRuston
Priority: critical Milestone: 2.2
Component: core Version:
Severity: critical Keywords:
Cc:

Description (Last modified by UdoBorkowski)

The scenario: set up the newTiddler macro to use a template that creates about 6 extended fields in the new tiddler. The problem: saving this new tiddler takes an extremely long period of time, almost long enough to make it a deal breaker in some cases.

Looking through the code drew my attention to these lines in Story.prototype.saveTiddler :

store.saveTiddler(title,newTitle,fields.text,config.options.txtUserName,minorUpdate ? undefined : newDate,fields.tags);
for (var n in fields) 
    if (!TiddlyWiki.isStandardField(n))
	store.setValue(newTitle,n,fields[n]);

Now correct me if I am wrong, but I believe the above code results in n+1 notifications to the store for a tiddler with n extended fields! So for a tiddler with 6 fields, we are looking at 7 notifications and possibly 7 screen redraws. Surely enough, sandwiching the setValue call between store.suspendNotifications and resumeNotifications alleviates the performance hit!

Reported by Saq in this discussion

Change History

06/01/07 17:57:00 changed by UdoBorkowski

  • summary changed from Story.prototype.saveTiddler sends too many notifications when custom fields are edited. to Story.prototype.saveTiddler sends too many notifications when extended fields are edited..

The suggested fix is to add a store.suspendNotifications and resumeNotifications frame around the loop and also to move the loop (with the frame) before the store.saveTiddler call. This way the extended fields are changed first and the notification handlers (called in store.saveTiddler) will also see these changes.

BTW: Even though the saveTiddler function has a fields parameter we cannot just pass in the fields from Story.saveTiddler. This is because the fields variable in Story.saveTiddler are all "edited" fields. I.e. it contains the standard fields like text or title and all the extended fields currently in the edit template. But it may miss other extended fields. The fields parameter for saveTiddler must contain all "extended fields" and only those. I.e. it must not contain standard fields. Therefore we need the extra loop the change the extended fields.

06/01/07 17:57:28 changed by UdoBorkowski

  • description changed.

08/02/07 22:04:40 changed by JeremyRuston

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in changeset:1495