From f25681d8b1acb49758e1c884e7a11a68df1d4a11 Mon Sep 17 00:00:00 2001 From: Dieter Eickstaedt Date: Wed, 4 Oct 2023 20:13:29 +0200 Subject: Fix/1207 deleted entries shown in interactive search (#1272) --- atuin-client/src/database.rs | 21 ++++++++++++++------- atuin-client/src/sync.rs | 6 +++--- 2 files changed, 17 insertions(+), 10 deletions(-) (limited to 'atuin-client') diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs index 1a3dea16..c75a32ce 100644 --- a/atuin-client/src/database.rs +++ b/atuin-client/src/database.rs @@ -80,16 +80,17 @@ pub trait Database: Send + Sync + 'static { context: &Context, max: Option, unique: bool, + include_deleted: bool, ) -> Result>; async fn range(&self, from: OffsetDateTime, to: OffsetDateTime) -> Result>; async fn update(&self, h: &History) -> Result<()>; - async fn history_count(&self) -> Result; + async fn history_count(&self, include_deleted: bool) -> Result; async fn last(&self) -> Result>; async fn before(&self, timestamp: OffsetDateTime, count: i64) -> Result>; - async fn delete(&self, mut h: History) -> Result<()>; + async fn delete(&self, h: History) -> Result<()>; async fn deleted(&self) -> Result>; // Yes I know, it's a lot. @@ -257,11 +258,15 @@ impl Database for Sqlite { context: &Context, max: Option, unique: bool, + include_deleted: bool, ) -> Result> { debug!("listing history"); let mut query = SqlBuilder::select_from(SqlName::new("history").alias("h").baquoted()); query.field("*").order_desc("timestamp"); + if !include_deleted { + query.and_where_is_null("deleted_at"); + } match filter { FilterMode::Global => &mut query, @@ -340,11 +345,13 @@ impl Database for Sqlite { Ok(res) } - async fn history_count(&self) -> Result { - let res: (i64,) = sqlx::query_as("select count(1) from history") - .fetch_one(&self.pool) - .await?; - + async fn history_count(&self, include_deleted: bool) -> Result { + let exclude_deleted: &str = if include_deleted { "" } else { "not" }; + let query = format!( + "select count(1) from history where deleted_at is {} null", + exclude_deleted + ); + let res: (i64,) = sqlx::query_as(&query).fetch_one(&self.pool).await?; Ok(res.0) } diff --git a/atuin-client/src/sync.rs b/atuin-client/src/sync.rs index ebfb47c1..c2fc75f9 100644 --- a/atuin-client/src/sync.rs +++ b/atuin-client/src/sync.rs @@ -48,7 +48,7 @@ async fn sync_download( let remote_deleted = HashSet::<&str>::from_iter(remote_status.deleted.iter().map(String::as_str)); - let initial_local = db.history_count().await?; + let initial_local = db.history_count(true).await?; let mut local_count = initial_local; let mut last_sync = if force { @@ -84,7 +84,7 @@ async fn sync_download( db.save_bulk(&history).await?; - local_count = db.history_count().await?; + local_count = db.history_count(true).await?; if history.len() < remote_status.page_size.try_into().unwrap() { break; @@ -137,7 +137,7 @@ async fn sync_upload( let initial_remote_count = client.count().await?; let mut remote_count = initial_remote_count; - let local_count = db.history_count().await?; + let local_count = db.history_count(true).await?; debug!("remote has {}, we have {}", remote_count, local_count); -- cgit v1.3.1