From 9c12bf2e8815dc9b42be62f1e1fd2932dd02938b Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 31 Oct 2026 19:53:27 +0100 Subject: use Automerge as Document instead of AutoCommit This allows a lot of operations to drop mut. --- src/remake/records.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/remake/records.rs') diff --git a/src/remake/records.rs b/src/remake/records.rs index fecae4c..55fa8a0 100644 --- a/src/remake/records.rs +++ b/src/remake/records.rs @@ -38,7 +38,7 @@ use crate::clock::UnixMillis; use crate::document::meta::{self, REMAKES, VOTES}; use crate::document::replica::Epoch; use crate::document::store::{self, StoreError}; -use crate::document::{ChangeHash, Document, Transactable}; +use crate::document::{ChangeHash, ReadDoc, Transactable}; /// One day, for retention defaults. const DAY_MS: u64 = 24 * 60 * 60 * 1000; @@ -337,13 +337,13 @@ pub(crate) fn record_path(id: &str, part: &str) -> Vec { } /// The record with this ID, if it exists and is readable, with its votes. -pub(crate) fn load(doc: &Document, id: &str) -> Option { +pub(crate) fn load(doc: &impl ReadDoc, id: &str) -> Option { let record = load_record(doc, id)?; Some(with_votes(id, record, &load_register(doc))) } /// All readable records, with their votes. -pub(crate) fn load_all(doc: &Document) -> Vec<(String, Record)> { +pub(crate) fn load_all(doc: &impl ReadDoc) -> Vec<(String, Record)> { let register = load_register(doc); store::keys_at(doc, &records_dir()) .unwrap_or_default() @@ -366,7 +366,7 @@ fn with_votes(id: &str, mut record: Record, register: &Register) -> Record { record } -fn load_record(doc: &Document, id: &str) -> Option { +fn load_record(doc: &impl ReadDoc, id: &str) -> Option { let value = match store::read_path(doc, &record_path(id, "")) { Ok(Some(value)) => value, Ok(None) => return None, @@ -390,7 +390,7 @@ fn load_record(doc: &Document, id: &str) -> Option { } /// A commit among concurrent decisions of remake `id` that disagree, if they do. -fn contested_decision(doc: &Document, id: &str) -> Option { +fn contested_decision(doc: &impl ReadDoc, id: &str) -> Option { let decisions: Vec = store::read_candidates(doc, &record_path(id, "decision")) .ok()? .into_iter() @@ -418,7 +418,7 @@ fn register_path(voter: &str) -> Vec { } /// The votes register; unreadable entries are skipped with a warning. -pub(crate) fn load_register(doc: &Document) -> Register { +pub(crate) fn load_register(doc: &impl ReadDoc) -> Register { store::keys_at(doc, &meta::path(&[VOTES])) .unwrap_or_default() .into_iter() @@ -503,6 +503,7 @@ pub(crate) fn decode_hex32(hex: &str) -> Option<[u8; 32]> { #[cfg(test)] mod tests { use super::*; + use crate::document::Document; use crate::document::testing::change; #[test] -- cgit v1.3.1