Delete stale projects after cleanup interval, via server foreign key cascade

This commit is contained in:
Max Brunsfeld 2022-12-20 17:27:27 -08:00
parent 55800fc696
commit 213be3d6bd
2 changed files with 2 additions and 40 deletions

View file

@ -123,34 +123,6 @@ impl Database {
.await
}
pub async fn delete_stale_projects(
&self,
environment: &str,
new_server_id: ServerId,
) -> Result<()> {
self.transaction(|tx| async move {
let stale_server_epochs = self
.stale_server_ids(environment, new_server_id, &tx)
.await?;
project_collaborator::Entity::delete_many()
.filter(
project_collaborator::Column::ConnectionServerId
.is_in(stale_server_epochs.iter().copied()),
)
.exec(&*tx)
.await?;
project::Entity::delete_many()
.filter(
project::Column::HostConnectionServerId
.is_in(stale_server_epochs.iter().copied()),
)
.exec(&*tx)
.await?;
Ok(())
})
.await
}
pub async fn stale_room_ids(
&self,
environment: &str,
@ -235,8 +207,8 @@ impl Database {
pub async fn delete_stale_servers(
&self,
new_server_id: ServerId,
environment: &str,
new_server_id: ServerId,
) -> Result<()> {
self.transaction(|tx| async move {
server::Entity::delete_many()

View file

@ -250,16 +250,6 @@ impl Server {
let live_kit_client = self.app_state.live_kit_client.clone();
let span = info_span!("start server");
let span_enter = span.enter();
tracing::info!("begin deleting stale projects");
app_state
.db
.delete_stale_projects(&app_state.config.zed_environment, server_id)
.await?;
tracing::info!("finish deleting stale projects");
drop(span_enter);
self.executor.spawn_detached(
async move {
tracing::info!("waiting for cleanup timeout");
@ -355,7 +345,7 @@ impl Server {
app_state
.db
.delete_stale_servers(server_id, &app_state.config.zed_environment)
.delete_stale_servers(&app_state.config.zed_environment, server_id)
.await
.trace_err();
}