aboutsummaryrefslogtreecommitdiffstats
path: root/src/document
diff options
context:
space:
mode:
Diffstat (limited to 'src/document')
-rw-r--r--src/document/bench.rs35
-rw-r--r--src/document/mod.rs4
2 files changed, 38 insertions, 1 deletions
diff --git a/src/document/bench.rs b/src/document/bench.rs
index 02b530d..908f919 100644
--- a/src/document/bench.rs
+++ b/src/document/bench.rs
@@ -29,6 +29,41 @@ fn sorted(mut heads: Vec<ChangeHash>) -> Vec<ChangeHash> {
heads
}
+/// `count` changes to `doc`, each writing one key under `data` (from `first` on), made
+/// at `at` and after.
+pub(crate) fn writes(doc: &mut Document, first: usize, count: usize, at: i64) {
+ for i in 0..count {
+ let mut transaction = doc.transaction();
+ let data = transaction
+ .get(ROOT, "data")
+ .expect("read")
+ .map(|(_, id)| id)
+ .unwrap_or_else(|| {
+ transaction
+ .put_object(ROOT, "data", automerge::ObjType::Map)
+ .expect("map")
+ });
+ transaction
+ .put(
+ &data,
+ format!("late{}", first + i),
+ ScalarValue::Int(i as i64),
+ )
+ .expect("write");
+ transaction
+ .commit_with(automerge::transaction::CommitOptions::default().with_time(at + i as i64));
+ }
+}
+
+/// A new document holding what `of` holds, as one change at time 0 (a snapshot).
+pub(crate) fn snapshot(of: &Document) -> Document {
+ let mut new = Document::new();
+ let mut transaction = new.transaction();
+ store::materialize_into(of, &mut transaction, &|_| false).expect("snapshot");
+ transaction.commit_with(automerge::transaction::CommitOptions::default().with_time(0));
+ new
+}
+
/// A document with `keys` keys under `data`, each written by a change of its own.
pub(crate) fn document(keys: usize) -> Document {
let mut doc = Document::new();
diff --git a/src/document/mod.rs b/src/document/mod.rs
index 21050ea..00ba4cb 100644
--- a/src/document/mod.rs
+++ b/src/document/mod.rs
@@ -8,7 +8,9 @@
/// like one (`Transactable`).
/// Only `document` and `remake` use Automerge itself (`architecture.md`, The document).
pub(crate) use automerge::transaction::{Transactable, Transaction};
-pub(crate) use automerge::{ActorId, Automerge as Document, Change, ChangeHash, ReadDoc};
+pub(crate) use automerge::{
+ ActorId, Automerge as Document, Change, ChangeHash, ReadDoc, ScalarValue,
+};
/// The whole document as bytes, as the engine saves it: a backup, the document
/// file's full save, the size a joining node downloads.