From 9c9168ac5b4cf92bc99207021263f02026b5fe09 Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Mon, 3 Jun 2024 16:34:54 +0800 Subject: [PATCH] fix: workspace id not match (#5454) --- .../flowy-document/src/event_handler.rs | 2 ++ .../rust-lib/flowy-document/src/manager.rs | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/frontend/rust-lib/flowy-document/src/event_handler.rs b/frontend/rust-lib/flowy-document/src/event_handler.rs index c87ed6ec79..029405c6cc 100644 --- a/frontend/rust-lib/flowy-document/src/event_handler.rs +++ b/frontend/rust-lib/flowy-document/src/event_handler.rs @@ -56,6 +56,8 @@ pub(crate) async fn open_document_handler( let manager = upgrade_document(manager)?; let params: OpenDocumentParams = data.into_inner().try_into()?; let doc_id = params.document_id; + manager.open_document(&doc_id).await?; + let document = manager.get_document(&doc_id).await?; let document_data = document.lock().get_document_data()?; data_result_ok(DocumentDataPB::from(document_data)) diff --git a/frontend/rust-lib/flowy-document/src/manager.rs b/frontend/rust-lib/flowy-document/src/manager.rs index 06639257d4..fb3b203b4e 100644 --- a/frontend/rust-lib/flowy-document/src/manager.rs +++ b/frontend/rust-lib/flowy-document/src/manager.rs @@ -77,7 +77,9 @@ impl DocumentManager { } pub async fn initialize(&self, _uid: i64) -> FlowyResult<()> { + trace!("initialize document manager"); self.documents.clear(); + self.removing_documents.clear(); Ok(()) } @@ -130,9 +132,6 @@ impl DocumentManager { } } - /// Returns Document for given object id - /// If the document does not exist in local disk, try get the doc state from the cloud. - /// If the document exists, open the document and cache it #[tracing::instrument(level = "info", skip(self), err)] pub async fn get_document(&self, doc_id: &str) -> FlowyResult> { if let Some(doc) = self.documents.get(doc_id).map(|item| item.value().clone()) { @@ -142,6 +141,17 @@ impl DocumentManager { if let Some(doc) = self.restore_document_from_removing(doc_id) { return Ok(doc); } + return Err(FlowyError::internal().with_context("Call open document first")); + } + + /// Returns Document for given object id + /// If the document does not exist in local disk, try get the doc state from the cloud. + /// If the document exists, open the document and cache it + #[tracing::instrument(level = "info", skip(self), err)] + async fn create_document_instance(&self, doc_id: &str) -> FlowyResult> { + if let Some(doc) = self.documents.get(doc_id).map(|item| item.value().clone()) { + return Ok(doc); + } let mut doc_state = DataSource::Disk; // If the document does not exist in local disk, try get the doc state from the cloud. This happens @@ -164,7 +174,12 @@ impl DocumentManager { } let uid = self.user_service.user_id()?; - event!(tracing::Level::DEBUG, "Initialize document: {}", doc_id); + event!( + tracing::Level::DEBUG, + "Initialize document: {}, workspace_id: {:?}", + doc_id, + self.user_service.workspace_id() + ); let collab = self .collab_for_document(uid, doc_id, doc_state, true) .await?; @@ -209,6 +224,8 @@ impl DocumentManager { if let Some(mutex_document) = self.restore_document_from_removing(doc_id) { mutex_document.start_init_sync(); } + + let _ = self.create_document_instance(doc_id).await?; Ok(()) } @@ -247,6 +264,7 @@ impl DocumentManager { Ok(()) } + #[instrument(level = "debug", skip_all, err)] pub async fn set_document_awareness_local_state( &self, doc_id: &str,