From d111282f7ec38bdcacca87dcddf77854ff599210 Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Sat, 24 Aug 2024 14:55:49 +0800 Subject: [PATCH] fix: panic when apply invalid update (#745) --- .../src/indexer/document_indexer.rs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/services/appflowy-collaborate/src/indexer/document_indexer.rs b/services/appflowy-collaborate/src/indexer/document_indexer.rs index b904cc51..0004ab85 100644 --- a/services/appflowy-collaborate/src/indexer/document_indexer.rs +++ b/services/appflowy-collaborate/src/indexer/document_indexer.rs @@ -53,14 +53,20 @@ impl Indexer for DocumentIndexer { object_id: &str, doc_state: Vec, ) -> Result, AppError> { - let collab = Collab::new_with_source( - CollabOrigin::Server, - object_id, - DataSource::DocStateV1(doc_state), - vec![], - false, - ) - .map_err(|e| AppError::Internal(e.into()))?; + let cloned_object_id = object_id.to_string(); + let collab = tokio::spawn(async move { + Collab::new_with_source( + CollabOrigin::Server, + &cloned_object_id, + DataSource::DocStateV1(doc_state), + vec![], + false, + ) + .map_err(|e| AppError::Internal(e.into())) + }) + .await + .map_err(|e| AppError::Internal(e.into()))??; + let document = Document::open(collab).map_err(|e| AppError::Internal(e.into()))?; let mut params = match Self::get_document_contents(&document) { Ok(result) => result,