Skip to content

Commit

Permalink
perf: apply update
Browse files Browse the repository at this point in the history
  • Loading branch information
forehalo committed Dec 22, 2023
1 parent dae318a commit 8a019e2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
7 changes: 3 additions & 4 deletions y-octo/src/doc/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,15 @@ impl Doc {
Ok(doc)
}

pub fn apply_update_from_binary_v1<T: AsRef<[u8]>>(&mut self, binary: T) -> JwstCodecResult<Update> {
pub fn apply_update_from_binary_v1<T: AsRef<[u8]>>(&mut self, binary: T) -> JwstCodecResult {
let mut decoder = RawDecoder::new(binary.as_ref());
let update = Update::read(&mut decoder)?;
self.apply_update(update)
}

pub fn apply_update(&mut self, mut update: Update) -> JwstCodecResult<Update> {
pub fn apply_update(&mut self, mut update: Update) -> JwstCodecResult {
let mut store = self.store.write().unwrap();
let mut retry = false;
let before_state = store.get_state_vector();
loop {
for (mut s, offset) in update.iter(store.get_state_vector()) {
if let Node::Item(item) = &mut s {
Expand Down Expand Up @@ -288,7 +287,7 @@ impl Doc {
}
}

store.diff_state_vector(&before_state, false)
Ok(())
}

pub fn keys(&self) -> Vec<String> {
Expand Down
12 changes: 2 additions & 10 deletions y-octo/src/doc/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,6 @@ impl DocStore {
let first_block = items.get(index).unwrap();
let offset = first_block.clock() - clock;
if offset != 0 {
// needs to implement Content split first
vec_struct_info.push_back(first_block.clone().split_at(offset)?.1);
} else {
vec_struct_info.push_back(first_block.clone());
Expand All @@ -800,17 +799,10 @@ impl DocStore {
let mut delete_set = DeleteSet::default();

for (client, nodes) in refs {
let ranges = nodes
nodes
.iter()
.filter(|n| n.deleted())
.map(|n| {
let clock = n.id().clock;
clock..clock + n.len()
})
.collect::<Vec<_>>();
if !ranges.is_empty() {
delete_set.batch_add_ranges(*client, ranges);
}
.for_each(|n| delete_set.add(*client, n.clock(), n.len()));
}

delete_set
Expand Down

0 comments on commit 8a019e2

Please sign in to comment.