Reduce serializability of project delete (#11628)

This may reduce locks when deleting projects.

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2024-05-09 16:17:13 -06:00 committed by GitHub
parent aa5113cd92
commit a3e75540af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 21 deletions

View file

@ -415,7 +415,7 @@ impl Database {
if is_serialization_error(error) && prev_attempt_count < SLEEPS.len() {
let base_delay = SLEEPS[prev_attempt_count];
let randomized_delay = base_delay * self.rng.lock().await.gen_range(0.5..=2.0);
log::info!(
log::warn!(
"retrying transaction after serialization error. delay: {} ms.",
randomized_delay
);

View file

@ -130,13 +130,21 @@ impl Database {
.await
}
pub async fn delete_project(&self, project_id: ProjectId) -> Result<()> {
self.weak_transaction(|tx| async move {
project::Entity::delete_by_id(project_id).exec(&*tx).await?;
Ok(())
})
.await
}
/// Unshares the given project.
pub async fn unshare_project(
&self,
project_id: ProjectId,
connection: ConnectionId,
user_id: Option<UserId>,
) -> Result<TransactionGuard<(Option<proto::Room>, Vec<ConnectionId>)>> {
) -> Result<TransactionGuard<(bool, Option<proto::Room>, Vec<ConnectionId>)>> {
self.project_transaction(project_id, |tx| async move {
let guest_connection_ids = self.project_guest_connection_ids(project_id, &tx).await?;
let project = project::Entity::find_by_id(project_id)
@ -149,10 +157,7 @@ impl Database {
None
};
if project.host_connection()? == connection {
project::Entity::delete(project.into_active_model())
.exec(&*tx)
.await?;
return Ok((room, guest_connection_ids));
return Ok((true, room, guest_connection_ids));
}
if let Some(dev_server_project_id) = project.dev_server_project_id {
if let Some(user_id) = user_id {
@ -169,7 +174,7 @@ impl Database {
})
.exec(&*tx)
.await?;
return Ok((room, guest_connection_ids));
return Ok((false, room, guest_connection_ids));
}
}

View file

@ -2032,12 +2032,15 @@ async fn unshare_project_internal(
user_id: Option<UserId>,
session: &Session,
) -> Result<()> {
let (room, guest_connection_ids) = &*session
let delete = {
let room_guard = session
.db()
.await
.unshare_project(project_id, connection_id, user_id)
.await?;
let (delete, room, guest_connection_ids) = &*room_guard;
let message = proto::UnshareProject {
project_id: project_id.to_proto(),
};
@ -2051,6 +2054,14 @@ async fn unshare_project_internal(
room_updated(room, &session.peer);
}
*delete
};
if delete {
let db = session.db().await;
db.delete_project(project_id).await?;
}
Ok(())
}