Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Don't wait for host's reply before broadcasting buffer updates to guests
Max Brunsfeld61d048cb25c0
diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rsindex ce5a6a0a1f7..16e7577d957 100644--- a/crates/collab/src/rpc.rs+++ b/crates/collab/src/rpc.rs@@ -1610,46 +1610,42 @@ async fn update_buffer() -> Result<()> {session.executor.record_backtrace();let project_id = ProjectId::from_proto(request.project_id);- let host_connection_id = {+ let mut guest_connection_ids;+ let mut host_connection_id = None;+ {let collaborators = session.db().await.project_collaborators(project_id, session.connection_id).await?;-- let host = collaborators- .iter()- .find(|collaborator| collaborator.is_host)- .ok_or_else(|| anyhow!("host not found"))?;- host.connection_id- };-- if host_connection_id != session.connection_id {- session- .peer- .forward_request(session.connection_id, host_connection_id, request.clone())- .await?;+ guest_connection_ids = Vec::with_capacity(collaborators.len() - 1);+ for collaborator in collaborators.iter() {+ if collaborator.is_host {+ host_connection_id = Some(collaborator.connection_id);+ } else {+ guest_connection_ids.push(collaborator.connection_id);+ }+ }}+ let host_connection_id = host_connection_id.ok_or_else(|| anyhow!("host not found"))?;session.executor.record_backtrace();- let collaborators = session- .db()- .await- .project_collaborators(project_id, session.connection_id)- .await?;-broadcast(Some(session.connection_id),- collaborators- .iter()- .filter(|collaborator| !collaborator.is_host)- .map(|collaborator| collaborator.connection_id),+ guest_connection_ids,|connection_id| {session.peer.forward_send(session.connection_id, connection_id, request.clone())},);+ if host_connection_id != session.connection_id {+ session+ .peer+ .forward_request(session.connection_id, host_connection_id, request.clone())+ .await?;+ }+response.send(proto::Ack {})?;Ok(())}