From 363e3cae4b97be7d93d4bbd78c3ab4d43b2a1857 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 14 Dec 2022 19:25:07 +0100 Subject: [PATCH] WIP --- crates/collab/src/db.rs | 20 +++++++++++++++++--- crates/collab/src/rpc.rs | 6 ++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rs index 424fc308d4..46ed2ce9f7 100644 --- a/crates/collab/src/db.rs +++ b/crates/collab/src/db.rs @@ -231,9 +231,23 @@ impl Database { .await } - fn delete_stale_servers(&self, environment: &str, new_epoch: ServerEpoch) -> Result<()> { - self.transaction(|tx| async { - server::Entity::delete_many().filter(Condition::all().add()) + pub async fn delete_stale_servers( + &self, + new_epoch: ServerEpoch, + environment: &str, + ) -> Result<()> { + self.transaction(|tx| async move { + server::Entity::delete_many() + .filter( + Condition::all().add( + server::Column::Environment + .eq(environment) + .add(server::Column::Epoch.ne(new_epoch)), + ), + ) + .exec(&*tx) + .await?; + Ok(()) }) .await } diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rs index 592e86cb45..d3a1c0ebf1 100644 --- a/crates/collab/src/rpc.rs +++ b/crates/collab/src/rpc.rs @@ -351,6 +351,12 @@ impl Server { } } } + + app_state + .db + .delete_stale_servers(epoch, &app_state.config.zed_environment) + .await + .trace_err(); } .instrument(span), );