Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I incrementally update doc_state and state_vector #4

Open
huang12zheng opened this issue Jul 19, 2023 · 1 comment
Open

How do I incrementally update doc_state and state_vector #4

huang12zheng opened this issue Jul 19, 2023 · 1 comment

Comments

@huang12zheng
Copy link

It seems to update doc_state and state_vector in full every time, how can it be incremental?

https://github.com/y-crdt/yrs-persistence/blob/a94b086b987a066d98b7d36a13bd540fca1722ee/yrs-kvstore/src/lib.rs

/// Inserts or updates a document given it's read transaction and name. lib0 v1 encoding is
    /// used for storing the document.
    ///
    /// This feature requires a write capabilities from the database transaction.
    fn insert_doc<K: AsRef<[u8]> + ?Sized, T: ReadTxn>(
        &self,
        name: &K,
        txn: &T,
    ) -> Result<(), Error> {
        let doc_state = txn.encode_diff_v1(&StateVector::default());
        let state_vector = txn.state_vector().encode_v1();
        self.insert_doc_raw_v1(name.as_ref(), &doc_state, &state_vector)
    }
@huang12zheng
Copy link
Author

huang12zheng commented Jul 19, 2023

In other words, whether doc_state and state_vector can be split into multiple KVs, then only the updated kv needs to be updated.

let mut diff = Self::diff_state_vectors(&local_sv, sv);

for (client, clock) in diff {
    let blocks = self.blocks.get(&client).unwrap();

    let start = {
        let clock = clock.max(blocks.first().id().clock); // make sure the first id exists
        blocks.find_pivot(clock).unwrap()
    }
    for i in (start + 1)..blocks.len() {
        let v = blocks.get(i);
        db.set("$name-$client-$i","%v")
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant