Start work on refreshing channel buffer collaborators on server restart

This commit is contained in:
Max Brunsfeld 2023-09-01 17:51:00 -07:00
parent e6babce556
commit 6827ddf97d
5 changed files with 73 additions and 15 deletions

View file

@ -123,10 +123,11 @@ impl Database {
// Find the collaborator record for this user's previous lost
// connection. Update it with the new connection id.
let Some(self_collaborator) = collaborators
.iter_mut()
.find(|c| c.user_id == user_id && c.connection_lost)
else {
let server_id = ServerId(connection_id.owner_id as i32);
let Some(self_collaborator) = collaborators.iter_mut().find(|c| {
c.user_id == user_id
&& (c.connection_lost || c.connection_server_id != server_id)
}) else {
continue;
};
let old_connection_id = self_collaborator.connection();
@ -195,6 +196,25 @@ impl Database {
.await
}
pub async fn refresh_channel_buffer(
&self,
channel_id: ChannelId,
server_id: ServerId,
) -> Result<RefreshedChannelBuffer> {
self.transaction(|tx| async move {
let mut connection_ids = Vec::new();
let mut removed_collaborators = Vec::new();
// TODO
Ok(RefreshedChannelBuffer {
connection_ids,
removed_collaborators,
})
})
.await
}
pub async fn leave_channel_buffer(
&self,
channel_id: ChannelId,

View file

@ -14,31 +14,48 @@ impl Database {
.await
}
pub async fn stale_room_ids(
pub async fn stale_server_resource_ids(
&self,
environment: &str,
new_server_id: ServerId,
) -> Result<Vec<RoomId>> {
) -> Result<(Vec<RoomId>, Vec<ChannelId>)> {
self.transaction(|tx| async move {
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
enum QueryAs {
enum QueryRoomIds {
RoomId,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
enum QueryChannelIds {
ChannelId,
}
let stale_server_epochs = self
.stale_server_ids(environment, new_server_id, &tx)
.await?;
Ok(room_participant::Entity::find()
let room_ids = room_participant::Entity::find()
.select_only()
.column(room_participant::Column::RoomId)
.distinct()
.filter(
room_participant::Column::AnsweringConnectionServerId
.is_in(stale_server_epochs),
.is_in(stale_server_epochs.iter().copied()),
)
.into_values::<_, QueryAs>()
.into_values::<_, QueryRoomIds>()
.all(&*tx)
.await?)
.await?;
let channel_ids = channel_buffer_collaborator::Entity::find()
.select_only()
.column(channel_buffer_collaborator::Column::ChannelId)
.distinct()
.filter(
channel_buffer_collaborator::Column::ConnectionServerId
.is_in(stale_server_epochs.iter().copied()),
)
.into_values::<_, QueryChannelIds>()
.all(&*tx)
.await?;
Ok((room_ids, channel_ids))
})
.await
}