mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-23 13:39:12 +00:00
fix: op counter
This commit is contained in:
parent
9fefd75fb6
commit
d1d242578f
4 changed files with 6 additions and 7 deletions
|
@ -68,20 +68,21 @@ impl ListContainer {
|
||||||
let id = store.next_id();
|
let id = store.next_id();
|
||||||
let mut offset = 0;
|
let mut offset = 0;
|
||||||
for item in op.items() {
|
for item in op.items() {
|
||||||
|
// TODO avoid clone
|
||||||
let item = item.clone().into_event_format();
|
let item = item.clone().into_event_format();
|
||||||
match item {
|
match item {
|
||||||
DeltaItem::Retain { len, .. } => index += len,
|
DeltaItem::Retain { len, .. } => index += len,
|
||||||
DeltaItem::Insert { value, .. } => {
|
DeltaItem::Insert { value, .. } => {
|
||||||
let len = value.len();
|
let len = value.len();
|
||||||
let id = id.inc(offset);
|
let id = id.inc(offset);
|
||||||
offset += 1;
|
offset += len as i32;
|
||||||
let op = self.apply_batch_insert(index, value, id);
|
let op = self.apply_batch_insert(index, value, id);
|
||||||
index += len;
|
index += len;
|
||||||
ops.push(op);
|
ops.push(op);
|
||||||
}
|
}
|
||||||
DeltaItem::Delete(len) => {
|
DeltaItem::Delete(len) => {
|
||||||
let id = id.inc(offset);
|
let id = id.inc(offset);
|
||||||
offset += 1;
|
offset += len as i32;
|
||||||
let op = self.apply_delete(index, len, id);
|
let op = self.apply_delete(index, len, id);
|
||||||
ops.push(op);
|
ops.push(op);
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,14 +65,14 @@ impl TextContainer {
|
||||||
DeltaItem::Insert { value, .. } => {
|
DeltaItem::Insert { value, .. } => {
|
||||||
let len = value.len();
|
let len = value.len();
|
||||||
let id = id.inc(offset);
|
let id = id.inc(offset);
|
||||||
offset += 1;
|
offset += len as i32;
|
||||||
let op = self.apply_insert(index, value, id);
|
let op = self.apply_insert(index, value, id);
|
||||||
index += len;
|
index += len;
|
||||||
ops.push(op);
|
ops.push(op);
|
||||||
}
|
}
|
||||||
DeltaItem::Delete(len) => {
|
DeltaItem::Delete(len) => {
|
||||||
let id = id.inc(offset);
|
let id = id.inc(offset);
|
||||||
offset += 1;
|
offset += *len as i32;
|
||||||
let op = self.apply_delete(index, *len, id);
|
let op = self.apply_delete(index, *len, id);
|
||||||
ops.push(op);
|
ops.push(op);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use tabled::{TableIteratorExt, Tabled};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
array_mut_ref,
|
array_mut_ref,
|
||||||
container::{registry::ContainerWrapper, temp::ContainerTemp, ContainerID},
|
container::{registry::ContainerWrapper, ContainerID},
|
||||||
delta::DeltaItem,
|
delta::DeltaItem,
|
||||||
event::{Diff, Observer},
|
event::{Diff, Observer},
|
||||||
id::ClientID,
|
id::ClientID,
|
||||||
|
|
|
@ -117,7 +117,6 @@ impl Transaction {
|
||||||
|
|
||||||
fn apply_ops_emit_event(&mut self) {
|
fn apply_ops_emit_event(&mut self) {
|
||||||
let compressed_op = std::mem::take(&mut self.compressed_op);
|
let compressed_op = std::mem::take(&mut self.compressed_op);
|
||||||
println!("compressed op {:?}", compressed_op);
|
|
||||||
let events = self.with_store_hierarchy_mut(|_txn, store, hierarchy| {
|
let events = self.with_store_hierarchy_mut(|_txn, store, hierarchy| {
|
||||||
let mut events = Vec::with_capacity(compressed_op.len());
|
let mut events = Vec::with_capacity(compressed_op.len());
|
||||||
for op in compressed_op {
|
for op in compressed_op {
|
||||||
|
@ -128,7 +127,6 @@ impl Transaction {
|
||||||
let container_id = container.id().clone();
|
let container_id = container.id().clone();
|
||||||
let type_ = container_id.container_type();
|
let type_ = container_id.container_type();
|
||||||
let store_ops = container.apply_txn_op(store, &op);
|
let store_ops = container.apply_txn_op(store, &op);
|
||||||
println!("store ops: {:?}", store_ops);
|
|
||||||
drop(container);
|
drop(container);
|
||||||
let (old_version, new_version) = store.append_local_ops(&store_ops);
|
let (old_version, new_version) = store.append_local_ops(&store_ops);
|
||||||
let new_version = new_version.into();
|
let new_version = new_version.into();
|
||||||
|
|
Loading…
Reference in a new issue