Ticket #278 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

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

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

Description (last modified by UdoBorkowski) (diff)

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

Changed 5 years ago 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.

Changed 5 years ago by UdoBorkowski

  • description modified (diff)

Changed 5 years ago by JeremyRuston

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

Fixed in changeset:1495

Note: See TracTickets for help on using tickets.