Continue the title with "Or we need to modify TWC core substantially?"
I used savetiddlers (only version 0.6 worked on my FireFox with macOS while 0.8 simply didn't) to save my TWC until FireFox was automatically updated to 68.0.1 last week.I learned all the code of savetiddlers and the saving mechanism of TWC while I was trying to fix some problems in savetiddlers. Although I'm not 100% sure, I'm suspicious about the asynchronous philosophy (as Yakov mentioned several times), at least for the current implementation of TWC core.To my understanding, saveMain() in TWC will set the dirty flag to false after saveFile() returns. Consider you are working a big TWC file, and saving take several seconds to accomplish. Between subsequent 2 savings, something will happen this way:1. You finish editing a tiddler A and click the done button. A save message will send to a saver.2. Because the saving operation is asynchronous, saveFile() immediately returns and then the dirty flag is set to false.3. The saver is downloading the new TWC file with the update tiddler A.4. Before the new TWC file downloading finishes, you edit another tiddler B and finish editing it and click the done button. The TWC core will load the original TWC file from the local file system WITHOUT the updated tiddler A, and send another saving message to the saver. Because in step 2 the dirty flag is set to false, this time the updated content contains only updated tiddler B and the ORIGINAL tidder A (tiddler A is thought to be already up-to-date).
5. The saver makes a new download operation where the TWC file to be saved contains only the original content with the updated tiddler B.6. A few seconds later, the first downloading finishes, now the local TWC file contains original content and updated tiddler A.7. Another few seconds later, the second downloading finishes, now the local TWC file contains original content and updated tiddler B.8. Note that ultimately you lose your work on tiddler A.To be honest, I haven't done any test to check whether the situation above will happen. But anyway, I think asynchronous saving needs more thorough thinking.To enable asynchronous loading and saving, I think we need to modify TWC core so that only if a "save-successful" message is received then the dirty flag could be set to false.
Is it how SaveTiddlers work? Because there's no such problem for TWC usual saving which is not tiddler-wise. Instead, it loads "original" (TW file), grabs the TW core and ignores the content completely and puts the current content into that core and than saves the file.
However, for TWC there's one more issue which is only applies to upgrading the core. In my tests of upgrading when Timimi is used as a saver, I've figured that the script is injected too late when the upgrading already tried to save and failed. Though, that was true for the script in dev environment and things (like you've noticed) may be different for production extension and I should retest this next week with the Timimi released with my patch for TWC support.
However, for TWC there's one more issue which is only applies to upgrading the core. In my tests of upgrading when Timimi is used as a saver, I've figured that the script is injected too late when the upgrading already tried to save and failed. Though, that was true for the script in dev environment and things (like you've noticed) may be different for production extension and I should retest this next week with the Timimi released with my patch for TWC support.Cool, looking forward to the solution to the upgrading support.
Other aspects (you may have already tested) we may need to pay attention to is to make sure the saver works for importing and exporting (I use ExportTiddlersPlugin for exporting, although it can't be found since http://www.tiddlytools.com/ is no longer accessible).
security.fileuri.strict_origin_policy setting in FireFox and Chrome can be launched with the --allow-file-access-from-files setting although I haven't tested it for a long time) – that's an ok approach but ideally we need a "saver" which proxies loading and makes it stable (well, MainTiddlyServer implements that partially; perhaps I'll propose that for Timimi too but for now I don't know how to setup and test it).Continue the title with "Or we need to modify TWC core substantially?"
To enable asynchronous loading and saving, I think we need to modify TWC core so that only if a "save-successful" message is received then the dirty flag could be set to false.
when saving the function recreateOriginal() is used to create the new twc image
With chrome and now with firefox (since version 68) loading files from 'file:/' is blocked due to security concerns
security.fileuri.strict_origin_policy in FF still makes it possible to load files via xhr through file: schema (I haven't tested much, but launching Chrome with the --allow-file-access-from-files param should do so as well).It would be better to remove the message box from the new image. At present savetiddlers will not work with a twc that already has a message box div - I will work around this and produce a new release.
Pengju Yan wrote
A really serious problem in savetiddlers is the mechanism of avoiding saving the same file while a previous saving is not finished. Check the dict "debouncing" in "contentscript.js".
In several cases, the dict "debouncing" was not cleared as expected then all my subsequent work was lost without my awareness (I enabled autosave and savebackups). I've been suffering from this time by time.
Also, the dirty flags of successive savings should be managed in a stack and cleaned in a proper way (delete certain dirty flags upon receiving certain "save-successful" messages).
Oh gosh, do you mean you had 2 subsequent saves with a little time gap between them? (could you describe your scenario so that I'm more aware of this potential problem? MainTiddlySaver hasn't debouncing implemented yet, but I never experienced this problem with content, only with options storage) If there's such problem, we should describe it in detail and refer to this in future development; I wasn't expecting anything like this in an extension saver (or may be the source of the problem is a bit different from what you describe?) We really need a reproducible scenario.
Yeah, I second this proposal (thinking about it for some time already), but this is a second level of IO improving which I'd address when a) I finish making TWC saving async and b) some documentation about IO/developing savers and editing (collaborating) workflow/infrastructure is established – because this is a more complicated idea and is less trivial to implement, especially when there's no docs describing it.
--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywikidev/0XbHgZks9OM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywikide...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/514de572-6502-48f6-9594-25ff4eada8cf%40googlegroups.com.