yjs / y-websocket

Websocket Connector for Yjs
https://docs.yjs.dev/ecosystem/connection-provider/y-websocket
MIT License
523 stars 261 forks source link

clear document from leveldb after writeState #96

Closed jlvdh closed 2 years ago

jlvdh commented 2 years ago

When persisting the document updates using persistence.bind() document updates are saved, when writeState is called the document is destroyed in memory but seems to live on in leveldb. Which would unnecessarily takes up space when it's already persisted to another db in writeState.

Describe the solution you'd like

after writeState is called (https://github.com/yjs/y-websocket/blob/master/bin/utils.js#L204):

    if (ldb) {
      ldb.clearDocument(doc.name)
    }

Huly®: YJS-516

dmonad commented 2 years ago

I don't think you need leveldb if you don't plan to persist the document..

If you use leveldb persistence, then it is supposed to keep track of the leveldb state.

If you use another persistence layer (e.g. your custom MongoDB persistence), then the state is supposed to be persisted in that layer.

You can combine two persistence layers (which is what I think you want to do), but then you have to handle a lot more edge cases like these. E.g., you need to load a document from both persistences, and make sure that a worker process writes updates from persistence A to persistence B when the y-websocket server is killed unexpectedly.

The default is not that you combine leveldb persistence with something else, so this is going to stay how it is.