mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-02 11:06:14 +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
|
||||
fn apply(&mut self, op: &OpProxy, store: &LogStore) {
|
||||
let new_op_id = op.id_last();
|
||||
let content = op.content_sliced();
|
||||
// TODO: may reduce following two into one op
|
||||
let common = store.find_common_ancestor(&[new_op_id], 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();
|
||||
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
|
||||
self.tracker = Tracker::new(common_vv);
|
||||
let path = store.find_path(&common, &latest_head);
|
||||
|
@ -120,7 +119,10 @@ impl Container for TextContainer {
|
|||
match effect {
|
||||
Effect::Del { pos, len } => self.state.delete_range(Some(pos), Some(pos + len)),
|
||||
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 rle::{HasLength, RleVec};
|
||||
use rle::{HasLength, RleVec, Sliceable};
|
||||
use serde::__private::de::Content;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::{
|
||||
|
@ -18,8 +19,8 @@ use crate::{
|
|||
container::{manager::ContainerManager, Container},
|
||||
dag::Dag,
|
||||
id::{ClientID, Counter},
|
||||
op::OpProxy,
|
||||
span::HasIdSpan,
|
||||
op::{OpContent, OpProxy},
|
||||
span::{HasIdSpan, IdSpan},
|
||||
Lamport, Op, Timestamp, ID,
|
||||
};
|
||||
|
||||
|
@ -193,6 +194,13 @@ impl LogStore {
|
|||
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]
|
||||
fn push_change(&mut self, change: Change) -> &Change {
|
||||
let v = self
|
||||
|
|
Loading…
Reference in a new issue