From 4c1b4953c17b48c19b57d6e9eb0247059f5de85f Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 18 Nov 2022 20:18:48 +0100 Subject: [PATCH] Remove version from `Room` We won't need it once we add the per-room lock. --- crates/call/src/room.rs | 10 --- .../20221109000000_test_schema.sql | 1 - .../20221111092550_reconnection_support.sql | 1 - crates/collab/src/db.rs | 71 +++++++++---------- crates/rpc/proto/zed.proto | 7 +- 5 files changed, 37 insertions(+), 53 deletions(-) diff --git a/crates/call/src/room.rs b/crates/call/src/room.rs index 8c1b0d9de0..f8a55a3a93 100644 --- a/crates/call/src/room.rs +++ b/crates/call/src/room.rs @@ -34,7 +34,6 @@ pub enum Event { pub struct Room { id: u64, - version: u64, live_kit: Option, status: RoomStatus, local_participant: LocalParticipant, @@ -62,7 +61,6 @@ impl Entity for Room { impl Room { fn new( id: u64, - version: u64, live_kit_connection_info: Option, client: Arc, user_store: ModelHandle, @@ -135,7 +133,6 @@ impl Room { Self { id, - version, live_kit: live_kit_room, status: RoomStatus::Online, participant_user_ids: Default::default(), @@ -164,7 +161,6 @@ impl Room { let room = cx.add_model(|cx| { Self::new( room_proto.id, - room_proto.version, response.live_kit_connection_info, client, user_store, @@ -209,7 +205,6 @@ impl Room { let room = cx.add_model(|cx| { Self::new( room_id, - 0, response.live_kit_connection_info, client, user_store, @@ -321,10 +316,6 @@ impl Room { futures::join!(remote_participants, pending_participants); this.update(&mut cx, |this, cx| { - if this.version >= room.version { - return; - } - this.participant_user_ids.clear(); if let Some(participant) = local_participant { @@ -429,7 +420,6 @@ impl Room { let _ = this.leave(cx); } - this.version = room.version; this.check_invariants(); cx.notify(); }); diff --git a/crates/collab/migrations.sqlite/20221109000000_test_schema.sql b/crates/collab/migrations.sqlite/20221109000000_test_schema.sql index 66925fddd5..02ca0c75a9 100644 --- a/crates/collab/migrations.sqlite/20221109000000_test_schema.sql +++ b/crates/collab/migrations.sqlite/20221109000000_test_schema.sql @@ -36,7 +36,6 @@ CREATE INDEX "index_contacts_user_id_b" ON "contacts" ("user_id_b"); CREATE TABLE "rooms" ( "id" INTEGER PRIMARY KEY, - "version" INTEGER NOT NULL, "live_kit_room" VARCHAR NOT NULL ); diff --git a/crates/collab/migrations/20221111092550_reconnection_support.sql b/crates/collab/migrations/20221111092550_reconnection_support.sql index 2b8f7824cb..b742f8e0cd 100644 --- a/crates/collab/migrations/20221111092550_reconnection_support.sql +++ b/crates/collab/migrations/20221111092550_reconnection_support.sql @@ -1,6 +1,5 @@ CREATE TABLE IF NOT EXISTS "rooms" ( "id" SERIAL PRIMARY KEY, - "version" INTEGER NOT NULL, "live_kit_room" VARCHAR NOT NULL ); diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rs index 6cb5373881..54d4497833 100644 --- a/crates/collab/src/db.rs +++ b/crates/collab/src/db.rs @@ -931,13 +931,12 @@ where let live_kit_room = nanoid::nanoid!(30); let room_id = sqlx::query_scalar( " - INSERT INTO rooms (live_kit_room, version) - VALUES ($1, $2) + INSERT INTO rooms (live_kit_room) + VALUES ($1) RETURNING id ", ) .bind(&live_kit_room) - .bind(0) .fetch_one(&mut tx) .await .map(RoomId)?; @@ -956,7 +955,9 @@ where .execute(&mut tx) .await?; - self.commit_room_transaction(room_id, tx).await + let room = self.get_room(room_id, &mut tx).await?; + tx.commit().await?; + Ok(room) }).await } @@ -983,7 +984,9 @@ where .execute(&mut tx) .await?; - let room = self.commit_room_transaction(room_id, tx).await?; + let room = self.get_room(room_id, &mut tx).await?; + tx.commit().await?; + let incoming_call = Self::build_incoming_call(&room, called_user_id) .ok_or_else(|| anyhow!("failed to build incoming call"))?; Ok((room, incoming_call)) @@ -1061,7 +1064,9 @@ where .execute(&mut tx) .await?; - self.commit_room_transaction(room_id, tx).await + let room = self.get_room(room_id, &mut tx).await?; + tx.commit().await?; + Ok(room) }) .await } @@ -1086,7 +1091,9 @@ where return Err(anyhow!("declining call on unexpected room"))?; } - self.commit_room_transaction(room_id, tx).await + let room = self.get_room(room_id, &mut tx).await?; + tx.commit().await?; + Ok(room) }) .await } @@ -1113,7 +1120,9 @@ where return Err(anyhow!("canceling call on unexpected room"))?; } - self.commit_room_transaction(room_id, tx).await + let room = self.get_room(room_id, &mut tx).await?; + tx.commit().await?; + Ok(room) }).await } @@ -1137,7 +1146,10 @@ where .bind(user_id) .fetch_one(&mut tx) .await?; - self.commit_room_transaction(room_id, tx).await + + let room = self.get_room(room_id, &mut tx).await?; + tx.commit().await?; + Ok(room) }) .await } @@ -1245,7 +1257,9 @@ where .execute(&mut tx) .await?; - let room = self.commit_room_transaction(room_id, tx).await?; + let room = self.get_room(room_id, &mut tx).await?; + tx.commit().await?; + Ok(Some(LeftRoom { room, left_projects, @@ -1302,32 +1316,13 @@ where .fetch_one(&mut tx) .await?; - self.commit_room_transaction(room_id, tx).await + let room = self.get_room(room_id, &mut tx).await?; + tx.commit().await?; + Ok(room) }) .await } - async fn commit_room_transaction( - &self, - room_id: RoomId, - mut tx: sqlx::Transaction<'_, D>, - ) -> Result { - sqlx::query( - " - UPDATE rooms - SET version = version + 1 - WHERE id = $1 - ", - ) - .bind(room_id) - .execute(&mut tx) - .await?; - let room = self.get_room(room_id, &mut tx).await?; - tx.commit().await?; - - Ok(room) - } - async fn get_guest_connection_ids( &self, project_id: ProjectId, @@ -1455,7 +1450,6 @@ where Ok(proto::Room { id: room.id.to_proto(), - version: room.version as u64, live_kit_room: room.live_kit_room, participants: participants.into_values().collect(), pending_participants, @@ -1565,7 +1559,9 @@ where .execute(&mut tx) .await?; - let room = self.commit_room_transaction(room_id, tx).await?; + let room = self.get_room(room_id, &mut tx).await?; + tx.commit().await?; + Ok((project_id, room)) }) .await @@ -1589,7 +1585,8 @@ where .bind(connection_id.0 as i32) .fetch_one(&mut tx) .await?; - let room = self.commit_room_transaction(room_id, tx).await?; + let room = self.get_room(room_id, &mut tx).await?; + tx.commit().await?; Ok((room, guest_connection_ids)) }) @@ -1666,7 +1663,8 @@ where query.execute(&mut tx).await?; let guest_connection_ids = self.get_guest_connection_ids(project_id, &mut tx).await?; - let room = self.commit_room_transaction(room_id, tx).await?; + let room = self.get_room(room_id, &mut tx).await?; + tx.commit().await?; Ok((room, guest_connection_ids)) }) @@ -2614,7 +2612,6 @@ id_type!(RoomId); #[derive(Clone, Debug, Default, FromRow, Serialize, PartialEq)] pub struct Room { pub id: RoomId, - pub version: i32, pub live_kit_room: String, } diff --git a/crates/rpc/proto/zed.proto b/crates/rpc/proto/zed.proto index 30c1c89e8f..6f26e0dfa1 100644 --- a/crates/rpc/proto/zed.proto +++ b/crates/rpc/proto/zed.proto @@ -160,10 +160,9 @@ message LeaveRoom {} message Room { uint64 id = 1; - uint64 version = 2; - repeated Participant participants = 3; - repeated PendingParticipant pending_participants = 4; - string live_kit_room = 5; + repeated Participant participants = 2; + repeated PendingParticipant pending_participants = 3; + string live_kit_room = 4; } message Participant {