There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
refactor: try merge update before output and after input
linonetwodc72b2ea117c
diff --git a/client-app/src-tauri/src/commands/document.rs b/client-app/src-tauri/src/commands/document.rsindex b92130918e..e469f52a0d 100644--- a/client-app/src-tauri/src/commands/document.rs+++ b/client-app/src-tauri/src/commands/document.rs@@ -52,13 +52,27 @@ pub async fn get_doc<'s>(parameters: GetDocumentParameter,) -> Result<GetDocumentResponse, String> {// TODO: check user permission+ let state = &state.0.lock().await;+ let doc_store = &state.doc_store;+ let doc_db = &state.doc_db;- if let Ok(all_updates_of_workspace) = &state.0.lock().await.doc_db.all(¶meters.id).await {+ if let Ok(all_updates_of_workspace) = doc_db.all(¶meters.id).await {+ let all_updates = all_updates_of_workspace+ .iter()+ .map(|model| model.blob.clone())+ .collect::<Vec<Vec<u8>>>();+ all_updates+ .iter()+ .for_each(|update_blob| {+ let mut tx = doc_store.doc().transact();+ let update = Update::decode_v1(&update_blob).unwrap();+ tx.apply_update(update);+ tx.commit();+ });+ let merged_update = doc_store.doc().transact().encode_update_v1();+ // TODO: store merged update hereOk(GetDocumentResponse {- updates: all_updates_of_workspace- .iter()- .map(|model| model.blob.clone())- .collect::<Vec<Vec<u8>>>(),+ updates: vec![merged_update],})} else {Err(format!(@@ -75,43 +89,15 @@ pub async fn update_y_document<'s>() -> Result<bool, String> {let state = &state.0.lock().await;let doc_store = &state.doc_store;- let doc_db = &state.doc_db;+ let mut tx = doc_store.doc().transact();let update = Update::decode_v1(¶meters.update).unwrap();- let mut decoder = DecoderV1::from(¶meters.update[..]);- for msg in MessageReader::new(&mut decoder) {- msg.ok().and_then(|msg| match msg {- Message::Sync(msg) => match msg {- SyncMessage::SyncStep1(sv) => {- Some(())- }- SyncMessage::SyncStep2(update) => {- Some(())- }- SyncMessage::Update(update) => {- let mut tx = doc_store.doc().transact();- tx.apply_update(Update::decode_v1(&update).unwrap());- tx.commit();- let merged_update = tx.encode_update_v1();- Some(())- }- },- Message::Auth(reason) => {- Some(())- }- Message::AwarenessQuery => {- Some(())- }- Message::Awareness(update) => {- Some(())- }- Message::Custom(tag, data) => {- Some(())- }- });- }- let merged_update = doc_store.doc().transact().encode_update_v1();+ tx.apply_update(update);+ let merged_update = tx.encode_update_v1();+ tx.commit();+ let doc_db = &state.doc_db;+doc_db- .insert(¶meters.id.clone(), &merged_update)+ .replace_with(¶meters.id.clone(), merged_update).await.ok();