silverbulletmd / silverbullet

The knowledge hacker's notebook
https://silverbullet.md
MIT License
2.27k stars 164 forks source link

Offline mode deletes content #5

Open Willyfrog opened 2 years ago

Willyfrog commented 2 years ago

open same page on desktop and mobile

on mobile

on desktop

on mobile

Expected: somehow both lines, on obsidian I see that it creates a separate page with a number 2 (mentioning for reference), a conflict like git would also work.

Observed: mobile wins and desktop line is lost.

zefhemel commented 2 years ago

Thanks for this. Indeed, there's no proper conflict detection at this stage.

zefhemel commented 2 years ago

A way to implement this is to add a type of “conditional put”. That is, “only write this page to disk, if the current timestamp matches X otherwise reject”. For the http_space_primitives (which is where this protocol is implemented between the browser and server) this may translate to an additional header to be sent as part of the PUT request.

Willyfrog commented 2 years ago

I’ve been thinking about this and wondering if we could use some sort of patching functionality when updating a page, generating a conflict if it can’t be automatically solved (as git does)

jzacsh commented 1 year ago

CRDTs maybe? I think the patch approach makes sense but will result in merge conflicts and the complex user experience the ensues, whereas CRDTs might solve this problem more smoothly. https://crdt.tech/implementations seems like a nice list of implementations and I know someone was getting to know the yjs lib in particular.

ngrilly commented 1 year ago

I think Obsidian is solving this problem without CRDTs, by just merging the server-side and the client-side content using a standard text merge algorithm like the one in difftools.

zefhemel commented 1 year ago

@ngrilly When you say Obsidian, you mean Obsidian Sync?

Willyfrog commented 1 year ago

the way to do that in obsidian might depend on the sync, I use iCloud to sync, and if I create a new file with the same name (like a daily note), it will create a daily 1 note and I'm the one expected to merge.

I haven't used the other syncing methods

ngrilly commented 1 year ago

@zefhemel Yes, Obsidian Sync.

infogulch commented 1 year ago

I really like the simplicity of the PUT idea, I think its the right layer to solve this problem:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match


That said, if the collab plugin is good enough to become the primary way to interact with the server then maybe shifting all effort to build on that would work too.

jzacsh commented 1 year ago

I agree it could be technically-simpler to use e-tag, but it's of course more complex for users to resolve (and depending on workflow this might happen a lot). Both are of course valid - it's an interesting trade-off to consider, for sure!

I wonder if the file reads/writes happen in such a way that this could be solved entirely in the plug space, and thus let multiple compete?


Also, possibly helpful anecdote: in logseq I can reproduce an issue like this at-will almost daily, due to my using syncthing to run multiple devices' instances of logseq (never actually in parallel, mind you). logseq just blindly deletes whatever is its buffer for the current file (the content I've been writing) when it encounters different content on disk (something that I know syncthing wrote there hours ago, well before I opened the file on this device). This is probably where my concern about user experience stems from; the race among files might be more common a user-experience than is obvious.

zefhemel commented 1 year ago

How I would imagine people use SB (at least I do) is to deploy just one instance (in your local network) and access it from multiple devices via the browser so you don't need to sync at all this avoiding such conflicts.

jzacsh commented 1 year ago

Yeah, that makes sense. I suppose I take my laptop places a lot though (to the office, out to a bar/cafe, etc.) so maybe that's why I run into this issue a lot.