diff options
Diffstat (limited to 'src/document/sync.rs')
| -rw-r--r-- | src/document/sync.rs | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/document/sync.rs b/src/document/sync.rs index b172dd1..394b10a 100644 --- a/src/document/sync.rs +++ b/src/document/sync.rs @@ -403,14 +403,14 @@ impl SyncSession { if have .last_sync .iter() - .all(|hash| doc.get_change_by_hash(hash).is_some()) + .all(|hash| crate::document::changes::holds(doc, hash)) { continue; } let mut known: Vec<crate::document::ChangeHash> = have .last_sync .iter() - .filter(|hash| doc.get_change_by_hash(hash).is_some()) + .filter(|hash| crate::document::changes::holds(doc, hash)) .chain(self.state.shared_heads.iter()) .copied() .collect(); @@ -435,7 +435,7 @@ impl SyncSession { let theirs = self.state.their_heads.as_ref()?; if theirs .iter() - .any(|hash| doc.get_change_by_hash(hash).is_none()) + .any(|hash| !crate::document::changes::holds(doc, hash)) { return None; } @@ -514,7 +514,8 @@ impl SyncSession { /// place of heads we lack (changes it has and we don't), the heads we share: the /// delta may then carry some it has, but nothing it lacks. fn delta_from(&self, doc: &Document) -> Vec<crate::document::ChangeHash> { - let known = |hash: &&crate::document::ChangeHash| doc.get_change_by_hash(hash).is_some(); + let known = + |hash: &&crate::document::ChangeHash| crate::document::changes::holds(doc, hash); let theirs = self.state.their_heads.as_deref().unwrap_or_default(); let mut from: Vec<_> = theirs.iter().filter(known).copied().collect(); if from.len() < theirs.len() { @@ -587,7 +588,7 @@ impl SyncSession { !heads.is_empty() && heads .iter() - .all(|head| doc.get_change_by_hash(head).is_some()) + .all(|head| crate::document::changes::holds(doc, head)) }) } @@ -711,7 +712,7 @@ impl SyncSession { let from: Vec<crate::document::ChangeHash> = from .iter() .copied() - .filter(|hash| doc.get_change_by_hash(hash).is_some()) + .filter(|hash| crate::document::changes::holds(doc, hash)) .collect(); let beyond: std::collections::HashMap<_, _> = doc .get_changes_meta(&from) @@ -796,7 +797,7 @@ impl SyncSession { self.state.their_heads.as_ref().is_some_and(|theirs| { theirs .iter() - .all(|hash| doc.get_change_by_hash(hash).is_some()) + .all(|hash| crate::document::changes::holds(doc, hash)) && heads.iter().any(|hash| !theirs.contains(hash)) }) } @@ -831,7 +832,7 @@ impl SyncSession { let older = self.state.their_heads.as_ref().is_some_and(|theirs| { theirs .iter() - .all(|hash| doc.get_change_by_hash(hash).is_some()) + .all(|hash| crate::document::changes::holds(doc, hash)) }); if !before.is_some_and(|before| older && level(&before.their_heads)) { return false; @@ -892,7 +893,7 @@ impl SyncSession { let before = self.state.sent_hashes.len(); self.state .sent_hashes - .retain(|hash| beyond.contains(hash) || doc.get_change_by_hash(hash).is_none()); + .retain(|hash| beyond.contains(hash) || !crate::document::changes::holds(doc, hash)); self.state.their_heads = Some(heads.to_vec()); self.state.shared_heads = heads.to_vec(); self.state.their_have = Some(vec![sync::Have { @@ -1541,7 +1542,7 @@ mod tests { Received::pushed(heads, changes).expect("decodes"), ) .unwrap(); - assert!(theirs.get_change_by_hash(&lost).is_none()); + assert!(!crate::document::changes::holds(&theirs, &lost)); let ask = b.generate(&theirs, now, bytes).expect("an ask"); assert_eq!(decode(&ask).unwrap().0.need, vec![lost]); } @@ -2056,7 +2057,7 @@ mod tests { let answer = decode(&answer).unwrap(); assert!(answer.carries_changes(), "with what the pusher lacks"); a.receive(&mut ours, answer).unwrap(); - assert!(ours.get_change_by_hash(&only_theirs[0]).is_some()); + assert!(crate::document::changes::holds(&ours, &only_theirs[0])); assert_eq!(ours.get_heads(), theirs.get_heads()); } |
