diff --git a/services/appflowy-collaborate/src/group/persistence.rs b/services/appflowy-collaborate/src/group/persistence.rs index aef15e1a..41abfc81 100644 --- a/services/appflowy-collaborate/src/group/persistence.rs +++ b/services/appflowy-collaborate/src/group/persistence.rs @@ -12,7 +12,7 @@ use collab::core::collab::{MutexCollab, WeakMutexCollab}; use std::sync::Arc; use std::time::Duration; use tokio::sync::mpsc; -use tokio::time::{interval, sleep}; +use tokio::time::interval; use tracing::{error, trace, warn}; pub(crate) struct GroupPersistence { @@ -55,9 +55,6 @@ where pub async fn run(self, mut destroy_group_rx: mpsc::Receiver) { let mut interval = interval(self.persistence_interval); - // TODO(nathan): remove this sleep when creating a new collab, applying all the updates - // workarounds for the issue that the collab doesn't contain the required data when first created - sleep(Duration::from_secs(5)).await; loop { tokio::select! { _ = interval.tick() => { diff --git a/src/api/workspace.rs b/src/api/workspace.rs index 14a6e620..cbf6a852 100644 --- a/src/api/workspace.rs +++ b/src/api/workspace.rs @@ -666,15 +666,27 @@ async fn create_collab_list_handler( if valid_items.is_empty() { return Err(AppError::InvalidRequest("Empty collab params list".to_string()).into()); } + let mut transaction = state + .pg_pool + .begin() + .await + .map_err(|err| AppError::Internal(anyhow!("Failed to start inserting collab: {}", err)))?; for params in valid_items { let _object_id = params.object_id.clone(); state .collab_access_control_storage - .insert_new_collab(&workspace_id, &uid, params) + .insert_new_collab_with_transaction(&workspace_id, &uid, params, &mut transaction) .await?; } + transaction.commit().await.map_err(|err| { + AppError::Internal(anyhow!( + "Failed to finish inserting list of collab: {}", + err + )) + })?; + Ok(Json(AppResponse::Ok())) }