From 1f3290ef80849d7262247a6dd87471259987cffd Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Tue, 4 Jun 2024 15:24:26 +0800 Subject: [PATCH] refactor: rm has_dependents field in change It's not longer required --- crates/loro-internal/src/change.rs | 4 ---- .../loro-internal/src/encoding/encode_reordered.rs | 1 - crates/loro-internal/src/oplog.rs | 12 ++---------- .../src/oplog/change_store/block_encode.rs | 1 - crates/loro-internal/src/txn.rs | 1 - crates/loro-wasm/deno.lock | 8 ++++++++ 6 files changed, 10 insertions(+), 17 deletions(-) diff --git a/crates/loro-internal/src/change.rs b/crates/loro-internal/src/change.rs index 4cc27254..a9e6a37e 100644 --- a/crates/loro-internal/src/change.rs +++ b/crates/loro-internal/src/change.rs @@ -35,8 +35,6 @@ pub struct Change { /// [Unix time](https://en.wikipedia.org/wiki/Unix_time) /// It is the number of seconds that have elapsed since 00:00:00 UTC on 1 January 1970. pub(crate) timestamp: Timestamp, - /// if it has dependents, it cannot merge with new changes - pub(crate) has_dependents: bool, } impl Change { @@ -53,7 +51,6 @@ impl Change { id, lamport, timestamp, - has_dependents: false, } } @@ -208,7 +205,6 @@ impl Slicea id: self.id.inc(from as Counter), lamport: self.lamport + from as Lamport, timestamp: self.timestamp, - has_dependents: self.has_dependents, } } } diff --git a/crates/loro-internal/src/encoding/encode_reordered.rs b/crates/loro-internal/src/encoding/encode_reordered.rs index 2b93791e..99564c3c 100644 --- a/crates/loro-internal/src/encoding/encode_reordered.rs +++ b/crates/loro-internal/src/encoding/encode_reordered.rs @@ -283,7 +283,6 @@ fn decode_changes<'a>( deps: Frontiers::with_capacity((deps_len + if dep_on_self { 1 } else { 0 }) as usize), lamport: 0, timestamp, - has_dependents: false, }; if dep_on_self { diff --git a/crates/loro-internal/src/oplog.rs b/crates/loro-internal/src/oplog.rs index 1443eb0b..0352f68d 100644 --- a/crates/loro-internal/src/oplog.rs +++ b/crates/loro-internal/src/oplog.rs @@ -262,10 +262,7 @@ impl OpLog { let timestamp_change = change.timestamp - last.timestamp; // TODO: make this a config - if !last.has_dependents - && change.deps_on_self() - && timestamp_change < merge_interval - { + if change.deps_on_self() && timestamp_change < merge_interval { for op in take(change.ops.vec_mut()) { last.ops.push(op); } @@ -379,11 +376,7 @@ impl OpLog { fn ensure_dep_on_change_end(&mut self, src: PeerID, dep: ID) { let changes = self.changes.get_mut(&dep.peer).unwrap(); match changes.binary_search_by(|c| c.ctr_last().cmp(&dep.counter)) { - Ok(index) => { - if src != dep.peer { - changes[index].has_dependents = true; - } - } + Ok(_) => {} Err(index) => { // This operation is slow in some rare cases, but I guess it's fine for now. // @@ -565,7 +558,6 @@ impl OpLog { deps: change.deps.clone(), lamport: change.lamport, timestamp: change.timestamp, - has_dependents: false, } } diff --git a/crates/loro-internal/src/oplog/change_store/block_encode.rs b/crates/loro-internal/src/oplog/change_store/block_encode.rs index bf20bf13..617d46da 100644 --- a/crates/loro-internal/src/oplog/change_store/block_encode.rs +++ b/crates/loro-internal/src/oplog/change_store/block_encode.rs @@ -542,7 +542,6 @@ pub fn decode_block( id: ID::new(header.peer, header.counters[i]), lamport: header.lamports[i], timestamp: timestamp_decoder.next().unwrap().unwrap() as Timestamp, - has_dependents: true, // FIXME: this field }) } diff --git a/crates/loro-internal/src/txn.rs b/crates/loro-internal/src/txn.rs index 747578d6..838e90d7 100644 --- a/crates/loro-internal/src/txn.rs +++ b/crates/loro-internal/src/txn.rs @@ -315,7 +315,6 @@ impl Transaction { self.timestamp .unwrap_or_else(|| oplog.get_timestamp_for_next_txn()), ), - has_dependents: false, }; let diff = if state.is_recording() { diff --git a/crates/loro-wasm/deno.lock b/crates/loro-wasm/deno.lock index 67ad4605..ef38bfde 100644 --- a/crates/loro-wasm/deno.lock +++ b/crates/loro-wasm/deno.lock @@ -27,5 +27,13 @@ "https://lra6z45nakk5lnu3yjchp7tftsdnwwikwr65ocha5eojfnlgu4sa.arweave.net/XEHs860CldW2m8JEd_5lnIbbWQq0fdcI4OkckrVmpyQ/path/separator.ts": "9dd15d46ff84a16e13554f56af7fee1f85f8d0f379efbbe60ac066a60561f036", "https://lra6z45nakk5lnu3yjchp7tftsdnwwikwr65ocha5eojfnlgu4sa.arweave.net/XEHs860CldW2m8JEd_5lnIbbWQq0fdcI4OkckrVmpyQ/path/win32.ts": "47114c941681ecbabab4ec355cb41d525fb5a14175cc47a5c76fdc5eaee2685a", "https://raw.githubusercontent.com/zxch3n/dirname/master/mod.ts": "79768be98329cc670a80bd4f5ce9800412944aba27f563a6314ae2c4589be229" + }, + "workspace": { + "packageJson": { + "dependencies": [ + "npm:vite-plugin-top-level-await@^1.2.2", + "npm:vite-plugin-wasm@^3.1.0" + ] + } } }