aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/api/store.rs6
-rw-r--r--src/document/bench.rs35
-rw-r--r--src/document/mod.rs4
-rw-r--r--src/remake/bench.rs40
4 files changed, 43 insertions, 42 deletions
diff --git a/src/api/store.rs b/src/api/store.rs
index d419d37..f6cf6fd 100644
--- a/src/api/store.rs
+++ b/src/api/store.rs
@@ -20,10 +20,10 @@ use tracing::{debug, error, instrument, warn};
use super::auth::AuthenticatedUser;
use super::{ApiError, store_status};
-use crate::document::ChangeHash;
use crate::document::meta;
use crate::document::store::{self, StoreError, paths_related};
use crate::document::typed::{self, JsonForm, Kind, TimestampFormat, Val};
+use crate::document::{ChangeHash, ScalarValue};
use crate::state::{AppState, ReadSource};
use crate::transport::Hex;
@@ -608,7 +608,7 @@ fn body_value(headers: &HeaderMap, body: &Bytes) -> Result<WriteBody, ApiError>
),
typed::TEXT => (
String::from_utf8(body.to_vec())
- .map(|text| Val::Scalar(automerge::ScalarValue::Str(text.into())))
+ .map(|text| Val::Scalar(ScalarValue::Str(text.into())))
.map_err(|_| bad("not UTF-8".to_owned()))?,
store::Sticky::All,
),
@@ -669,7 +669,7 @@ pub(crate) async fn post_store_entry(
.map_err(|e| store_status(e, "Failed to increment a counter"))?;
return Ok(with_heads(
{
- let counter = automerge::ScalarValue::counter(value);
+ let counter = ScalarValue::counter(value);
let held = store::Held {
kind: Kind::Counter,
value: Some(counter),
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.
diff --git a/src/remake/bench.rs b/src/remake/bench.rs
index f262601..fa9f358 100644
--- a/src/remake/bench.rs
+++ b/src/remake/bench.rs
@@ -8,40 +8,9 @@
use std::time::Instant;
-use automerge::transaction::Transactable;
-use automerge::{ObjType, ROOT, ReadDoc, ScalarValue};
-
use super::delta::{Superseded, replay_newest};
use super::kind::Translator;
-use crate::document::Document;
-use crate::document::bench::{document, median};
-use crate::document::store;
-
-/// `count` changes to `doc`, each writing one key under `data` (from `first` on), made
-/// at `at` and after.
-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", 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));
- }
-}
+use crate::document::bench::{document, median, snapshot, writes};
/// `late` writes made to the old document after `keys` keys, carried into a new one
/// holding those keys (as a snapshot, at time 0) and `newer` writes of its own made
@@ -53,12 +22,7 @@ fn replay(keys: usize, late: usize, newer: usize) {
writes(&mut old, 0, late, 1_000);
let after = old.get_heads();
- let mut new = Document::new();
- {
- let mut transaction = new.transaction();
- store::materialize_into(&old_base, &mut transaction, &|_| false).expect("snapshot");
- transaction.commit_with(automerge::transaction::CommitOptions::default().with_time(0));
- }
+ let mut new = snapshot(&old_base);
writes(&mut new, late, newer, 2_000);
let took = median(5, || {