diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-01-16 11:25:09 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-16 11:25:09 +0000 |
| commit | a2578c4521d4615d8265744ab51a1cc4f291605e (patch) | |
| tree | 26fb3da7a1d7312691703919cc700e433bbd1220 /atuin-client/src/record | |
| parent | fix(sync): save sync time when it starts, not ends (#1573) (diff) | |
| download | atuin-a2578c4521d4615d8265744ab51a1cc4f291605e.zip | |
feat: add history rebuild (#1575)
* feat: add history rebuild
This adds a function that will
1. List all history from the store
2. Segment by create/delete
3. Insert all creates into the database
4. Delete all deleted
This replaces the old history sync.
Presently it's incomplete. There is no incremental rebuild, it can only
do the entire thing at once.
This is ran by `atuin store rebuild history`
* fix tests
* add incremental sync
* add auto sync
Diffstat (limited to 'atuin-client/src/record')
| -rw-r--r-- | atuin-client/src/record/store.rs | 5 | ||||
| -rw-r--r-- | atuin-client/src/record/sync.rs | 17 |
2 files changed, 11 insertions, 11 deletions
diff --git a/atuin-client/src/record/store.rs b/atuin-client/src/record/store.rs index a5c156d6..efe2eb4a 100644 --- a/atuin-client/src/record/store.rs +++ b/atuin-client/src/record/store.rs @@ -2,6 +2,7 @@ use async_trait::async_trait; use eyre::Result; use atuin_common::record::{EncryptedData, HostId, Record, RecordId, RecordIdx, RecordStatus}; + /// A record store stores records /// In more detail - we tend to need to process this into _another_ format to actually query it. /// As is, the record store is intended as the source of truth for arbitratry data, which could @@ -44,8 +45,6 @@ pub trait Store { async fn status(&self) -> Result<RecordStatus>; - /// Get every start record for a given tag, regardless of host. - /// Useful when actually operating on synchronized data, and will often have conflict - /// resolution applied. + /// Get all records for a given tag async fn all_tagged(&self, tag: &str) -> Result<Vec<Record<EncryptedData>>>; } diff --git a/atuin-client/src/record/sync.rs b/atuin-client/src/record/sync.rs index 2694e0ff..19b8dd1b 100644 --- a/atuin-client/src/record/sync.rs +++ b/atuin-client/src/record/sync.rs @@ -7,7 +7,7 @@ use thiserror::Error; use super::store::Store; use crate::{api_client::Client, settings::Settings}; -use atuin_common::record::{Diff, HostId, RecordIdx, RecordStatus}; +use atuin_common::record::{Diff, HostId, RecordId, RecordIdx, RecordStatus}; #[derive(Error, Debug)] pub enum SyncError { @@ -198,11 +198,12 @@ async fn sync_download( tag: String, local: Option<RecordIdx>, remote: RecordIdx, -) -> Result<i64, SyncError> { +) -> Result<Vec<RecordId>, SyncError> { let local = local.unwrap_or(0); let expected = remote - local; let download_page_size = 100; let mut progress = 0; + let mut ret = Vec::new(); println!( "Downloading {} records from {}/{}", @@ -230,6 +231,8 @@ async fn sync_download( expected ); + ret.extend(page.iter().map(|f| f.id)); + progress += page.len() as u64; if progress >= expected { @@ -237,14 +240,14 @@ async fn sync_download( } } - Ok(progress as i64) + Ok(ret) } pub async fn sync_remote( operations: Vec<Operation>, local_store: &impl Store, settings: &Settings, -) -> Result<(i64, i64), SyncError> { +) -> Result<(i64, Vec<RecordId>), SyncError> { let client = Client::new( &settings.sync_address, &settings.session_token, @@ -254,7 +257,7 @@ pub async fn sync_remote( .expect("failed to create client"); let mut uploaded = 0; - let mut downloaded = 0; + let mut downloaded = Vec::new(); // this can totally run in parallel, but lets get it working first for i in operations { @@ -271,9 +274,7 @@ pub async fn sync_remote( tag, local, remote, - } => { - downloaded += sync_download(local_store, &client, host, tag, local, remote).await? - } + } => downloaded = sync_download(local_store, &client, host, tag, local, remote).await?, Operation::Noop { .. } => continue, } |
