fix: should not use snapshot importing when it's inside a batch importing (#436)

* fix: should not use snapshot importing when it's inside a batch importing

* chore: bk
This commit is contained in:
Zixuan Chen 2024-08-28 00:06:24 +08:00 committed by GitHub
parent c36664e784
commit 7cf54e8aa3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 27 additions and 2 deletions

View file

@ -0,0 +1,6 @@
---
"loro-wasm": patch
"loro-crdt": patch
---
Fix batch importing with snapshot

View file

@ -216,7 +216,12 @@ impl LoroDoc {
/// Is the document empty? (no ops)
#[inline(always)]
pub fn can_reset_with_snapshot(&self) -> bool {
self.oplog.lock().unwrap().is_empty() && self.state.lock().unwrap().is_empty()
let oplog = self.oplog.lock().unwrap();
if oplog.batch_importing {
return false;
}
oplog.is_empty() && self.state.lock().unwrap().is_empty()
}
/// Whether [OpLog] and [DocState] are detached.

View file

@ -213,7 +213,7 @@ impl LoroDoc {
/// Import a batch of updates/snapshot.
///
/// The data can be in arbitrary order. The import result will be the same.
pub fn import_batch(&mut self, bytes: &[Vec<u8>]) -> LoroResult<()> {
pub fn import_batch(&self, bytes: &[Vec<u8>]) -> LoroResult<()> {
self.doc.import_batch(bytes)
}

View file

@ -0,0 +1,14 @@
use loro::LoroDoc;
#[ctor::ctor]
fn init() {
dev_utils::setup_test_log();
}
#[test]
fn issue_0() {
let bytes = include_bytes!("./issue_0.bin");
let doc = LoroDoc::new();
doc.import_batch(&[bytes.into()]).unwrap();
doc.export_snapshot();
}

Binary file not shown.