mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-08 21:47:41 +00:00
feat: get op content from store
This commit is contained in:
parent
d1e1143c58
commit
4f2f07dd32
2 changed files with 16 additions and 6 deletions
|
@ -89,7 +89,6 @@ impl Container for TextContainer {
|
||||||
// TODO: move main logic to tracker module
|
// TODO: move main logic to tracker module
|
||||||
fn apply(&mut self, op: &OpProxy, store: &LogStore) {
|
fn apply(&mut self, op: &OpProxy, store: &LogStore) {
|
||||||
let new_op_id = op.id_last();
|
let new_op_id = op.id_last();
|
||||||
let content = op.content_sliced();
|
|
||||||
// TODO: may reduce following two into one op
|
// TODO: may reduce following two into one op
|
||||||
let common = store.find_common_ancestor(&[new_op_id], store.frontier());
|
let common = store.find_common_ancestor(&[new_op_id], store.frontier());
|
||||||
let path_to_store_head = store.find_path(&common, store.frontier());
|
let path_to_store_head = store.find_path(&common, store.frontier());
|
||||||
|
@ -98,7 +97,7 @@ impl Container for TextContainer {
|
||||||
|
|
||||||
let mut latest_head: SmallVec<[ID; 2]> = store.frontier().into();
|
let mut latest_head: SmallVec<[ID; 2]> = store.frontier().into();
|
||||||
latest_head.push(new_op_id);
|
latest_head.push(new_op_id);
|
||||||
if common.len() == 0 || !common.iter().all(|x| self.tracker.contains(*x)) {
|
if common.is_empty() || !common.iter().all(|x| self.tracker.contains(*x)) {
|
||||||
// stage 1
|
// stage 1
|
||||||
self.tracker = Tracker::new(common_vv);
|
self.tracker = Tracker::new(common_vv);
|
||||||
let path = store.find_path(&common, &latest_head);
|
let path = store.find_path(&common, &latest_head);
|
||||||
|
@ -120,7 +119,10 @@ impl Container for TextContainer {
|
||||||
match effect {
|
match effect {
|
||||||
Effect::Del { pos, len } => self.state.delete_range(Some(pos), Some(pos + len)),
|
Effect::Del { pos, len } => self.state.delete_range(Some(pos), Some(pos + len)),
|
||||||
Effect::Ins { pos, content } => {
|
Effect::Ins { pos, content } => {
|
||||||
todo!("need to find the span from store / keep the list slice in the tracker");
|
let content = store.get_op_content(content).unwrap();
|
||||||
|
let list_content = content.as_normal().unwrap().as_list().unwrap();
|
||||||
|
let insert_content = list_content.as_insert().unwrap().0;
|
||||||
|
self.state.insert(pos, insert_content.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,8 @@ use std::{
|
||||||
|
|
||||||
use fxhash::FxHashMap;
|
use fxhash::FxHashMap;
|
||||||
|
|
||||||
use rle::{HasLength, RleVec};
|
use rle::{HasLength, RleVec, Sliceable};
|
||||||
|
use serde::__private::de::Content;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -18,8 +19,8 @@ use crate::{
|
||||||
container::{manager::ContainerManager, Container},
|
container::{manager::ContainerManager, Container},
|
||||||
dag::Dag,
|
dag::Dag,
|
||||||
id::{ClientID, Counter},
|
id::{ClientID, Counter},
|
||||||
op::OpProxy,
|
op::{OpContent, OpProxy},
|
||||||
span::HasIdSpan,
|
span::{HasIdSpan, IdSpan},
|
||||||
Lamport, Op, Timestamp, ID,
|
Lamport, Op, Timestamp, ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -193,6 +194,13 @@ impl LogStore {
|
||||||
todo!("update vv");
|
todo!("update vv");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_op_content(&self, id_span: IdSpan) -> Option<OpContent> {
|
||||||
|
let changes = self.changes.get(&id_span.client_id)?;
|
||||||
|
let result = changes.get(id_span.counter.start as usize)?;
|
||||||
|
let result = result.element.ops.get(result.offset)?;
|
||||||
|
Some(result.element.content.slice(0, id_span.len()))
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn push_change(&mut self, change: Change) -> &Change {
|
fn push_change(&mut self, change: Change) -> &Change {
|
||||||
let v = self
|
let v = self
|
||||||
|
|
Loading…
Reference in a new issue