aboutsummaryrefslogtreecommitdiffstats
path: root/src/document/changes.rs
diff options
context:
space:
mode:
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.