Remove version from Room

We won't need it once we add the per-room lock.
This commit is contained in:
Antonio Scandurra 2022-11-18 20:18:48 +01:00
parent c3d556d9bd
commit 4c1b4953c1
5 changed files with 37 additions and 53 deletions

View File

@ -34,7 +34,6 @@ pub enum Event {
pub struct Room {
id: u64,
version: u64,
live_kit: Option<LiveKitRoom>,
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<proto::LiveKitConnectionInfo>,
client: Arc<Client>,
user_store: ModelHandle<UserStore>,
@ -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();
});

View File

@ -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
);

View File

@ -1,6 +1,5 @@
CREATE TABLE IF NOT EXISTS "rooms" (
"id" SERIAL PRIMARY KEY,
"version" INTEGER NOT NULL,
"live_kit_room" VARCHAR NOT NULL
);

View File

@ -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<proto::Room> {
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,
}

View File

@ -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 {