Skip to content

Commit

Permalink
fix: should not use snapshot importing when it's inside a batch impor…
Browse files Browse the repository at this point in the history
…ting (#436)

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

* chore: bk
  • Loading branch information
zxch3n authored Aug 27, 2024
1 parent c36664e commit 7cf54e8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/strong-walls-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"loro-wasm": patch
"loro-crdt": patch
---

Fix batch importing with snapshot
7 changes: 6 additions & 1 deletion crates/loro-internal/src/loro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion crates/loro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
14 changes: 14 additions & 0 deletions crates/loro/tests/issue.rs
Original file line number Diff line number Diff line change
@@ -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 added crates/loro/tests/issue_0.bin
Binary file not shown.

0 comments on commit 7cf54e8

Please sign in to comment.