chore: update create collab list api endpoint (#657)

* chore: update create collab list api endpoint

* chore: clippy

* chore: fix compile
This commit is contained in:
Nathan.fooo 2024-06-27 15:41:10 +08:00 committed by GitHub
parent 80e1dce500
commit 50ed9f4a6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 5 deletions

View File

@ -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<S> {
@ -55,9 +55,6 @@ where
pub async fn run(self, mut destroy_group_rx: mpsc::Receiver<MutexCollab>) {
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() => {

View File

@ -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()))
}