mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-06 12:25:03 +00:00
refactor: add import batch interface
This commit is contained in:
parent
95daf02a29
commit
680a0e1ce2
1 changed files with 34 additions and 0 deletions
|
@ -74,6 +74,25 @@ impl LogStore {
|
|||
|
||||
Ok(self.import(changes))
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
pub fn import_updates_batch(
|
||||
&mut self,
|
||||
batch: &[Vec<u8>],
|
||||
) -> Result<Vec<RawEvent>, postcard::Error> {
|
||||
let mut changes: RemoteClientChanges = Default::default();
|
||||
for input in batch {
|
||||
let updates: Updates = postcard::from_bytes(input)?;
|
||||
for encoded in updates.changes {
|
||||
changes
|
||||
.entry(encoded.meta.client)
|
||||
.or_default()
|
||||
.append(&mut convert_encoded_to_changes(encoded));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(self.import(changes))
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_changes_to_encoded<I>(mut changes: I) -> EncodedClientChanges
|
||||
|
@ -207,4 +226,19 @@ impl LoroCore {
|
|||
debug_log::group_end!();
|
||||
ans
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
pub fn import_updates_batch(&mut self, input: &[Vec<u8>]) -> Result<(), LoroError> {
|
||||
debug_log::group!("Import updates at {}", self.client_id());
|
||||
let ans = self.log_store.write().unwrap().import_updates_batch(input);
|
||||
let ans = match ans {
|
||||
Ok(events) => {
|
||||
self.notify(events);
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => Err(LoroError::DecodeError(err.to_string().into_boxed_str())),
|
||||
};
|
||||
debug_log::group_end!();
|
||||
ans
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue