aboutsummaryrefslogtreecommitdiffstats
path: root/src/document/changes.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 18:07:07 +0100
committertv <tv@krebsco.de>2026-10-31 18:07:07 +0100
commit4a9f4507f3161791f80c8c25a6f0e9ccd3649c2c (patch)
tree7de1e540b12879364105e275feb07a5b129251a5 /src/document/changes.rs
parent4ea5867047d869ea6a33efd6a47a2adc2340114e (diff)
move all automerge references to document
Diffstat (limited to 'src/document/changes.rs')
-rw-r--r--src/document/changes.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/document/changes.rs b/src/document/changes.rs
index d369c79..655063b 100644
--- a/src/document/changes.rs
+++ b/src/document/changes.rs
@@ -8,6 +8,26 @@ use anyhow::{Context, Result, anyhow, bail};
use super::{Change, ChangeHash, Document};
+/// Those of `heads` that `doc` doesn't have. (Looking a change up needs the document
+/// mutably.)
+pub(crate) fn missing(doc: &mut Document, heads: &[ChangeHash]) -> Vec<ChangeHash> {
+ heads
+ .iter()
+ .copied()
+ .filter(|head| doc.get_change_by_hash(head).is_none())
+ .collect()
+}
+
+/// When the changes after `since` were committed, in Unix milliseconds by their
+/// writers' clocks (`Replica::commit`); changes without a time (snapshots) left out.
+pub(crate) fn commit_times(doc: &mut Document, since: &[ChangeHash]) -> Vec<i64> {
+ doc.get_changes(since)
+ .iter()
+ .map(|change| change.timestamp())
+ .filter(|&time| time > 0)
+ .collect()
+}
+
/// The change `hash` as the document encodes it; None if `doc` doesn't have it.
pub(crate) fn change_bytes(doc: &mut Document, hash: &ChangeHash) -> Option<Vec<u8>> {
doc.get_change_by_hash(hash)
@@ -33,7 +53,7 @@ pub(crate) fn delta_bytes(
from: &[ChangeHash],
to: &[ChangeHash],
) -> Option<Vec<u8>> {
- if to.iter().any(|head| doc.get_change_by_hash(head).is_none()) {
+ if !missing(doc, to).is_empty() {
return None;
}
// Heads of `from` we don't have can't hide anything we have.