twcloud / tiddlyweb-sse

MIT License
10 stars 3 forks source link

Does this work already in the core tw? #1

Closed linonetwo closed 3 years ago

linonetwo commented 3 years ago

@Arlen22 I see you have opened a series of PRs, and the last one is https://github.com/Jermolene/TiddlyWiki5/pull/5882 . IIRC you have one of them merged?

I'm writing watch-fs plugin that will update nodejs cache if fs changed, and I may need SSE to get this change sync to the client.

So do I need to depend on this plugin to get my plugin working?

Arlen22 commented 3 years ago

The two are not related. You can use this to make changes instantly propagate to the browser, otherwise the syncer already polls for changes every minute, so you wouldn't need this for that part to work. But if you want them to propagate quickly, this would help.

Make sure you watch out for edit conflicts though. You'll have to test it all to figure out what works. There are a few community solutions for that part already.

Also, on the filesystem side of things, there is already a mechanism in TiddlyWiki for the server to poll for changes every minute, or more often if you are using some form of watcher. I think you should take that into consideration and perhaps only check the disk when the syncer calls for it (getSkinnyTiddlers). You can look at the tiddlyweb adaptor to understand how that works.

Arlen22 commented 3 years ago

The really proper solution would be to load the datafolder from disk again using the same code that runs on startup and then compare that to the wiki to make sure nothing changed. If you take a look at the loadTiddlersNode function, that should get you started. Everywhere it says $tw.wiki.addTiddlers or something like that you would change it to check the current wiki to make sure it is exactly the same as the data that just got loaded.

https://github.com/Jermolene/TiddlyWiki5/blob/master/boot/boot.js#L2205

Arlen22 commented 3 years ago

You also have to look at and modify $tw.loadWikiTiddlers and $tw.loadPlugins as they both add tiddlers to the wiki.

But now that I'm writing it out, that's a pretty big project, but then I guess so is any other way of doing it. Anyway, just thought I'd mention my perspective on that since I worked with the server side of things a lot with TiddlyServer.

linonetwo commented 3 years ago

Thank you for these detailed suggestions!

there is already a mechanism in TiddlyWiki for the server to poll for changes every minute

Can you point out the code? I have never seen this get working, or perhaps I was too eager to see this gets working.

Arlen22 commented 3 years ago

If you take a look at how the tiddlyweb plugin works, it polls the server every minute. This comes from the core/modules/syncer.js file calling getSkinnyTiddlers on the tiddlyweb adaptor every minute.

linonetwo commented 3 years ago

Ok, I thought you mean it polls filesystem, turnout I still have to implement fs watching by my self... And use your sse plugin to sync change to the client. Thanks!

Arlen22 commented 3 years ago

You still need tiddlyweb to sync changes to the client. My plugin just changes the behaviour to poll whenever the server changes instead of polling every minute. It still polls every 10 hours or something like that.