Remove version from Room
We won't need it once we add the per-room lock.
This commit is contained in:
parent
c3d556d9bd
commit
4c1b4953c1
5 changed files with 37 additions and 53 deletions
|
@ -34,7 +34,6 @@ pub enum Event {
|
||||||
|
|
||||||
pub struct Room {
|
pub struct Room {
|
||||||
id: u64,
|
id: u64,
|
||||||
version: u64,
|
|
||||||
live_kit: Option<LiveKitRoom>,
|
live_kit: Option<LiveKitRoom>,
|
||||||
status: RoomStatus,
|
status: RoomStatus,
|
||||||
local_participant: LocalParticipant,
|
local_participant: LocalParticipant,
|
||||||
|
@ -62,7 +61,6 @@ impl Entity for Room {
|
||||||
impl Room {
|
impl Room {
|
||||||
fn new(
|
fn new(
|
||||||
id: u64,
|
id: u64,
|
||||||
version: u64,
|
|
||||||
live_kit_connection_info: Option<proto::LiveKitConnectionInfo>,
|
live_kit_connection_info: Option<proto::LiveKitConnectionInfo>,
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
user_store: ModelHandle<UserStore>,
|
user_store: ModelHandle<UserStore>,
|
||||||
|
@ -135,7 +133,6 @@ impl Room {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
version,
|
|
||||||
live_kit: live_kit_room,
|
live_kit: live_kit_room,
|
||||||
status: RoomStatus::Online,
|
status: RoomStatus::Online,
|
||||||
participant_user_ids: Default::default(),
|
participant_user_ids: Default::default(),
|
||||||
|
@ -164,7 +161,6 @@ impl Room {
|
||||||
let room = cx.add_model(|cx| {
|
let room = cx.add_model(|cx| {
|
||||||
Self::new(
|
Self::new(
|
||||||
room_proto.id,
|
room_proto.id,
|
||||||
room_proto.version,
|
|
||||||
response.live_kit_connection_info,
|
response.live_kit_connection_info,
|
||||||
client,
|
client,
|
||||||
user_store,
|
user_store,
|
||||||
|
@ -209,7 +205,6 @@ impl Room {
|
||||||
let room = cx.add_model(|cx| {
|
let room = cx.add_model(|cx| {
|
||||||
Self::new(
|
Self::new(
|
||||||
room_id,
|
room_id,
|
||||||
0,
|
|
||||||
response.live_kit_connection_info,
|
response.live_kit_connection_info,
|
||||||
client,
|
client,
|
||||||
user_store,
|
user_store,
|
||||||
|
@ -321,10 +316,6 @@ impl Room {
|
||||||
futures::join!(remote_participants, pending_participants);
|
futures::join!(remote_participants, pending_participants);
|
||||||
|
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
if this.version >= room.version {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.participant_user_ids.clear();
|
this.participant_user_ids.clear();
|
||||||
|
|
||||||
if let Some(participant) = local_participant {
|
if let Some(participant) = local_participant {
|
||||||
|
@ -429,7 +420,6 @@ impl Room {
|
||||||
let _ = this.leave(cx);
|
let _ = this.leave(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.version = room.version;
|
|
||||||
this.check_invariants();
|
this.check_invariants();
|
||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
|
|
|
@ -36,7 +36,6 @@ CREATE INDEX "index_contacts_user_id_b" ON "contacts" ("user_id_b");
|
||||||
|
|
||||||
CREATE TABLE "rooms" (
|
CREATE TABLE "rooms" (
|
||||||
"id" INTEGER PRIMARY KEY,
|
"id" INTEGER PRIMARY KEY,
|
||||||
"version" INTEGER NOT NULL,
|
|
||||||
"live_kit_room" VARCHAR NOT NULL
|
"live_kit_room" VARCHAR NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
CREATE TABLE IF NOT EXISTS "rooms" (
|
CREATE TABLE IF NOT EXISTS "rooms" (
|
||||||
"id" SERIAL PRIMARY KEY,
|
"id" SERIAL PRIMARY KEY,
|
||||||
"version" INTEGER NOT NULL,
|
|
||||||
"live_kit_room" VARCHAR NOT NULL
|
"live_kit_room" VARCHAR NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -931,13 +931,12 @@ where
|
||||||
let live_kit_room = nanoid::nanoid!(30);
|
let live_kit_room = nanoid::nanoid!(30);
|
||||||
let room_id = sqlx::query_scalar(
|
let room_id = sqlx::query_scalar(
|
||||||
"
|
"
|
||||||
INSERT INTO rooms (live_kit_room, version)
|
INSERT INTO rooms (live_kit_room)
|
||||||
VALUES ($1, $2)
|
VALUES ($1)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.bind(&live_kit_room)
|
.bind(&live_kit_room)
|
||||||
.bind(0)
|
|
||||||
.fetch_one(&mut tx)
|
.fetch_one(&mut tx)
|
||||||
.await
|
.await
|
||||||
.map(RoomId)?;
|
.map(RoomId)?;
|
||||||
|
@ -956,7 +955,9 @@ where
|
||||||
.execute(&mut tx)
|
.execute(&mut tx)
|
||||||
.await?;
|
.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
|
}).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -983,7 +984,9 @@ where
|
||||||
.execute(&mut tx)
|
.execute(&mut tx)
|
||||||
.await?;
|
.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)
|
let incoming_call = Self::build_incoming_call(&room, called_user_id)
|
||||||
.ok_or_else(|| anyhow!("failed to build incoming call"))?;
|
.ok_or_else(|| anyhow!("failed to build incoming call"))?;
|
||||||
Ok((room, incoming_call))
|
Ok((room, incoming_call))
|
||||||
|
@ -1061,7 +1064,9 @@ where
|
||||||
.execute(&mut tx)
|
.execute(&mut tx)
|
||||||
.await?;
|
.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
|
.await
|
||||||
}
|
}
|
||||||
|
@ -1086,7 +1091,9 @@ where
|
||||||
return Err(anyhow!("declining call on unexpected room"))?;
|
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
|
.await
|
||||||
}
|
}
|
||||||
|
@ -1113,7 +1120,9 @@ where
|
||||||
return Err(anyhow!("canceling call on unexpected room"))?;
|
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
|
}).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1137,7 +1146,10 @@ where
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
.fetch_one(&mut tx)
|
.fetch_one(&mut tx)
|
||||||
.await?;
|
.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
|
.await
|
||||||
}
|
}
|
||||||
|
@ -1245,7 +1257,9 @@ where
|
||||||
.execute(&mut tx)
|
.execute(&mut tx)
|
||||||
.await?;
|
.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 {
|
Ok(Some(LeftRoom {
|
||||||
room,
|
room,
|
||||||
left_projects,
|
left_projects,
|
||||||
|
@ -1302,32 +1316,13 @@ where
|
||||||
.fetch_one(&mut tx)
|
.fetch_one(&mut tx)
|
||||||
.await?;
|
.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
|
.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(
|
async fn get_guest_connection_ids(
|
||||||
&self,
|
&self,
|
||||||
project_id: ProjectId,
|
project_id: ProjectId,
|
||||||
|
@ -1455,7 +1450,6 @@ where
|
||||||
|
|
||||||
Ok(proto::Room {
|
Ok(proto::Room {
|
||||||
id: room.id.to_proto(),
|
id: room.id.to_proto(),
|
||||||
version: room.version as u64,
|
|
||||||
live_kit_room: room.live_kit_room,
|
live_kit_room: room.live_kit_room,
|
||||||
participants: participants.into_values().collect(),
|
participants: participants.into_values().collect(),
|
||||||
pending_participants,
|
pending_participants,
|
||||||
|
@ -1565,7 +1559,9 @@ where
|
||||||
.execute(&mut tx)
|
.execute(&mut tx)
|
||||||
.await?;
|
.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))
|
Ok((project_id, room))
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
|
@ -1589,7 +1585,8 @@ where
|
||||||
.bind(connection_id.0 as i32)
|
.bind(connection_id.0 as i32)
|
||||||
.fetch_one(&mut tx)
|
.fetch_one(&mut tx)
|
||||||
.await?;
|
.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))
|
Ok((room, guest_connection_ids))
|
||||||
})
|
})
|
||||||
|
@ -1666,7 +1663,8 @@ where
|
||||||
query.execute(&mut tx).await?;
|
query.execute(&mut tx).await?;
|
||||||
|
|
||||||
let guest_connection_ids = self.get_guest_connection_ids(project_id, &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))
|
Ok((room, guest_connection_ids))
|
||||||
})
|
})
|
||||||
|
@ -2614,7 +2612,6 @@ id_type!(RoomId);
|
||||||
#[derive(Clone, Debug, Default, FromRow, Serialize, PartialEq)]
|
#[derive(Clone, Debug, Default, FromRow, Serialize, PartialEq)]
|
||||||
pub struct Room {
|
pub struct Room {
|
||||||
pub id: RoomId,
|
pub id: RoomId,
|
||||||
pub version: i32,
|
|
||||||
pub live_kit_room: String,
|
pub live_kit_room: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,10 +160,9 @@ message LeaveRoom {}
|
||||||
|
|
||||||
message Room {
|
message Room {
|
||||||
uint64 id = 1;
|
uint64 id = 1;
|
||||||
uint64 version = 2;
|
repeated Participant participants = 2;
|
||||||
repeated Participant participants = 3;
|
repeated PendingParticipant pending_participants = 3;
|
||||||
repeated PendingParticipant pending_participants = 4;
|
string live_kit_room = 4;
|
||||||
string live_kit_room = 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message Participant {
|
message Participant {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue