From b15602307ef2c9d2149ce076245bf4e1aa34261f Mon Sep 17 00:00:00 2001 From: leeeon233 Date: Mon, 30 Jan 2023 18:16:09 +0800 Subject: [PATCH] feat: change cfg api --- crates/loro-internal/src/log_store.rs | 30 ++++++++++++++++++++------- crates/loro-internal/src/loro.rs | 27 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/crates/loro-internal/src/log_store.rs b/crates/loro-internal/src/log_store.rs index 930b6b0a..45ccfa85 100644 --- a/crates/loro-internal/src/log_store.rs +++ b/crates/loro-internal/src/log_store.rs @@ -222,13 +222,6 @@ impl LogStore { &self.frontiers } - fn get_change_merge_cfg(&self) -> ChangeMergeCfg { - ChangeMergeCfg { - max_change_length: self.cfg.change.max_change_length, - max_change_interval: self.cfg.change.max_change_interval, - } - } - /// this method would not get the container and apply op pub fn append_local_ops(&mut self, ops: &[Op]) -> (SmallVec<[ID; 2]>, &[ID]) { let old_version = self.frontiers.clone(); @@ -304,6 +297,29 @@ impl LogStore { &self.vv } + fn get_change_merge_cfg(&self) -> ChangeMergeCfg { + ChangeMergeCfg { + max_change_length: self.cfg.change.max_change_length, + max_change_interval: self.cfg.change.max_change_interval, + } + } + + pub(crate) fn max_change_length(&mut self, max_change_length: usize) { + self.cfg.change.max_change_length = max_change_length + } + + pub(crate) fn max_change_interval(&mut self, max_change_interval: usize) { + self.cfg.change.max_change_interval = max_change_interval + } + + pub(crate) fn gc(&mut self, gc: bool) { + self.cfg.gc.gc = gc; + } + + pub(crate) fn snapshot_interval(&mut self, snapshot_interval: u64) { + self.cfg.gc.snapshot_interval = snapshot_interval; + } + #[cfg(feature = "test_utils")] pub fn debug_inspect(&mut self) { println!( diff --git a/crates/loro-internal/src/loro.rs b/crates/loro-internal/src/loro.rs index 4d1342a8..eeca1422 100644 --- a/crates/loro-internal/src/loro.rs +++ b/crates/loro-internal/src/loro.rs @@ -148,4 +148,31 @@ impl LoroCore { pub fn notify(&self, events: Vec) { Hierarchy::send_notifications_without_lock(self.hierarchy.clone(), events) } + + // config + + pub fn max_change_length(&mut self, max_change_length: usize) { + self.log_store + .write() + .unwrap() + .max_change_length(max_change_length); + } + + pub fn max_change_interval(&mut self, max_change_interval: usize) { + self.log_store + .write() + .unwrap() + .max_change_interval(max_change_interval); + } + + pub fn gc(&mut self, gc: bool) { + self.log_store.write().unwrap().gc(gc) + } + + pub fn snapshot_interval(&mut self, snapshot_interval: u64) { + self.log_store + .write() + .unwrap() + .snapshot_interval(snapshot_interval); + } }