diff --git a/services/appflowy-collaborate/src/command.rs b/services/appflowy-collaborate/src/command.rs index bfb3cab0..ebab9c64 100644 --- a/services/appflowy-collaborate/src/command.rs +++ b/services/appflowy-collaborate/src/command.rs @@ -37,6 +37,8 @@ pub enum CollaborationCommand { }, } +const BATCH_GET_ENCODE_COLLAB_CONCURRENCY: usize = 10; + pub(crate) fn spawn_collaboration_command( mut command_recv: CLCommandReceiver, group_sender_by_object_id: &Arc>, @@ -80,13 +82,13 @@ pub(crate) fn spawn_collaboration_command( } }) }) + .buffer_unordered(BATCH_GET_ENCODE_COLLAB_CONCURRENCY) .collect::>() .await; let mut outputs: HashMap = HashMap::new(); - for task in tasks { - let result = task.await; - if let Ok((object_id, Some(encoded_collab))) = result { + for (object_id, encoded_collab) in tasks.into_iter().flatten() { + if let Some(encoded_collab) = encoded_collab { outputs.insert(object_id, encoded_collab); } }