fix: limit concurrency level of batch get encode collab (#892)

This commit is contained in:
Khor Shu Heng 2024-10-17 13:29:27 +08:00 committed by GitHub
parent 9942e68089
commit 8ab5da4aef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 3 deletions

View File

@ -37,6 +37,8 @@ pub enum CollaborationCommand {
}, },
} }
const BATCH_GET_ENCODE_COLLAB_CONCURRENCY: usize = 10;
pub(crate) fn spawn_collaboration_command<S>( pub(crate) fn spawn_collaboration_command<S>(
mut command_recv: CLCommandReceiver, mut command_recv: CLCommandReceiver,
group_sender_by_object_id: &Arc<DashMap<String, GroupCommandSender>>, group_sender_by_object_id: &Arc<DashMap<String, GroupCommandSender>>,
@ -80,13 +82,13 @@ pub(crate) fn spawn_collaboration_command<S>(
} }
}) })
}) })
.buffer_unordered(BATCH_GET_ENCODE_COLLAB_CONCURRENCY)
.collect::<Vec<_>>() .collect::<Vec<_>>()
.await; .await;
let mut outputs: HashMap<String, EncodedCollab> = HashMap::new(); let mut outputs: HashMap<String, EncodedCollab> = HashMap::new();
for task in tasks { for (object_id, encoded_collab) in tasks.into_iter().flatten() {
let result = task.await; if let Some(encoded_collab) = encoded_collab {
if let Ok((object_id, Some(encoded_collab))) = result {
outputs.insert(object_id, encoded_collab); outputs.insert(object_id, encoded_collab);
} }
} }