mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-11 21:13:02 +00:00
Delete stale projects after cleanup interval, via server foreign key cascade
This commit is contained in:
parent
55800fc696
commit
213be3d6bd
2 changed files with 2 additions and 40 deletions
|
@ -123,34 +123,6 @@ impl Database {
|
||||||
.await
|
.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(
|
pub async fn stale_room_ids(
|
||||||
&self,
|
&self,
|
||||||
environment: &str,
|
environment: &str,
|
||||||
|
@ -235,8 +207,8 @@ impl Database {
|
||||||
|
|
||||||
pub async fn delete_stale_servers(
|
pub async fn delete_stale_servers(
|
||||||
&self,
|
&self,
|
||||||
new_server_id: ServerId,
|
|
||||||
environment: &str,
|
environment: &str,
|
||||||
|
new_server_id: ServerId,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.transaction(|tx| async move {
|
self.transaction(|tx| async move {
|
||||||
server::Entity::delete_many()
|
server::Entity::delete_many()
|
||||||
|
|
|
@ -250,16 +250,6 @@ impl Server {
|
||||||
let live_kit_client = self.app_state.live_kit_client.clone();
|
let live_kit_client = self.app_state.live_kit_client.clone();
|
||||||
|
|
||||||
let span = info_span!("start server");
|
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(
|
self.executor.spawn_detached(
|
||||||
async move {
|
async move {
|
||||||
tracing::info!("waiting for cleanup timeout");
|
tracing::info!("waiting for cleanup timeout");
|
||||||
|
@ -355,7 +345,7 @@ impl Server {
|
||||||
|
|
||||||
app_state
|
app_state
|
||||||
.db
|
.db
|
||||||
.delete_stale_servers(server_id, &app_state.config.zed_environment)
|
.delete_stale_servers(&app_state.config.zed_environment, server_id)
|
||||||
.await
|
.await
|
||||||
.trace_err();
|
.trace_err();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue