From 79622cf698a1c831341f6e3906005ddbb54c55d8 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Fri, 24 Mar 2023 09:04:57 +0000 Subject: Delete all instances of a command (#797) * Delete all instances of a command Our search command will de-dupe results by default. But... This isn't great for deleting! You don't want to run it over-and-over-and-over until all commands are deleted. Loop the query, and keep on deleting what it returns until they are all gone. * Optimize delete upload It was running a request for every element, on every sync lol Only push a delete if needed Future: push all deletes in one request --- atuin-client/src/database.rs | 1 + atuin-client/src/sync.rs | 7 +++++++ 2 files changed, 8 insertions(+) (limited to 'atuin-client/src') diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs index 4135646c..bb4d9dfa 100644 --- a/atuin-client/src/database.rs +++ b/atuin-client/src/database.rs @@ -460,6 +460,7 @@ impl Database for Sqlite { ]) .group_by("command") .group_by("exit") + .and_where("deleted_at is null") .order_desc("timestamp"); let query = query.sql().expect("bug in list query. please report"); diff --git a/atuin-client/src/sync.rs b/atuin-client/src/sync.rs index 1c0acaf8..474084d7 100644 --- a/atuin-client/src/sync.rs +++ b/atuin-client/src/sync.rs @@ -111,6 +111,9 @@ async fn sync_upload( ) -> Result<()> { debug!("starting sync upload"); + let remote_status = client.status().await?; + let remote_deleted: HashSet = HashSet::from_iter(remote_status.deleted.clone()); + let initial_remote_count = client.count().await?; let mut remote_count = initial_remote_count; @@ -157,6 +160,10 @@ async fn sync_upload( let deleted = db.deleted().await?; for i in deleted { + if remote_deleted.contains(&i.id) { + continue; + } + info!("deleting {} on remote", i.id); client.delete_history(i).await?; } -- cgit v1.3.1