diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2023-03-20 09:26:54 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-20 09:26:54 +0000 |
| commit | dcd77749dd1fdf6b0c8183bfbdf4f97bf238ebe4 (patch) | |
| tree | 97c623911eeb52da65c2b3fd80092f2c86f3dd18 /atuin-client/src/sync.rs | |
| parent | skim-demo (#695) (diff) | |
| download | atuin-dcd77749dd1fdf6b0c8183bfbdf4f97bf238ebe4.zip | |
Add history deletion (#791)
* Drop events. I'd still like to do them, but differently
* Start adding delete api stuff
* Set mailmap
* Delete delete delete
* Fix tests
* Make clippy happy
Diffstat (limited to 'atuin-client/src/sync.rs')
| -rw-r--r-- | atuin-client/src/sync.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/atuin-client/src/sync.rs b/atuin-client/src/sync.rs index 94ae24c4..1c0acaf8 100644 --- a/atuin-client/src/sync.rs +++ b/atuin-client/src/sync.rs @@ -1,4 +1,6 @@ +use std::collections::HashSet; use std::convert::TryInto; +use std::iter::FromIterator; use chrono::prelude::*; use eyre::Result; @@ -37,7 +39,11 @@ async fn sync_download( ) -> Result<(i64, i64)> { debug!("starting sync download"); - let remote_count = client.count().await?; + let remote_status = client.status().await?; + let remote_count = remote_status.count; + + // useful to ensure we don't even save something that hasn't yet been synced + deleted + let remote_deleted = HashSet::from_iter(remote_status.deleted.clone()); let initial_local = db.history_count().await?; let mut local_count = initial_local; @@ -54,7 +60,12 @@ async fn sync_download( while remote_count > local_count { let page = client - .get_history(last_sync, last_timestamp, host.clone()) + .get_history( + last_sync, + last_timestamp, + host.clone(), + remote_deleted.clone(), + ) .await?; db.save_bulk(&page).await?; @@ -81,6 +92,13 @@ async fn sync_download( } } + for i in remote_status.deleted { + // we will update the stored history to have this data + // pretty much everything can be nullified + let h = db.load(i.as_str()).await?; + db.delete(h).await?; + } + Ok((local_count - initial_local, local_count)) } @@ -136,12 +154,17 @@ async fn sync_upload( debug!("upload cursor: {:?}", cursor); } + let deleted = db.deleted().await?; + + for i in deleted { + info!("deleting {} on remote", i.id); + client.delete_history(i).await?; + } + Ok(()) } pub async fn sync(settings: &Settings, force: bool, db: &mut (impl Database + Send)) -> Result<()> { - db.merge_events().await?; - let client = api_client::Client::new( &settings.sync_address, &settings.session_token, |
