For versioning, should I store snapshot or document copies?

Hi there! I’m quite new to yjs, so I might be thinking the wrong things.

I’m building a text editor and I want to be able to go back and forth between documents versions, so far I’ve done that by making a copy of the YDocument and storing it on sqlite, but I’m unsure if it is the right thing to do, I’ve seen snapshots, but I’m unsure if I need to use them or not.

Can you you help me understand?

Hi, welcome.

I recommend reading this thread: How to recover to the specified version

It contains code snippets, links to relevant discussions, and links to example demos.

Since a Doc contains the entire version history, storing multiple copies of the entire Doc at different points in time is not the best approach. You’re better off storing the Doc once, and then storing a snapshot for each point that you would like to be able to restore.

A snapshot is just a state vector + delete set, so it takes up very little space, but it requires an existing YDoc to work.

Thank you so much for the answer!

1 Like