aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-client/src/record/sync.rs
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2024-01-16 11:25:09 +0000
committerGitHub <noreply@github.com>2024-01-16 11:25:09 +0000
commita2578c4521d4615d8265744ab51a1cc4f291605e (patch)
tree26fb3da7a1d7312691703919cc700e433bbd1220 /atuin-client/src/record/sync.rs
parentfix(sync): save sync time when it starts, not ends (#1573) (diff)
downloadatuin-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/sync.rs')
-rw-r--r--atuin-client/src/record/sync.rs17
1 files changed, 9 insertions, 8 deletions
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,
}