summaryrefslogtreecommitdiffstats
path: root/atuin-client/src/sync.rs
diff options
context:
space:
mode:
authorEllie Huxtable <e@elm.sh>2021-04-21 18:13:51 +0100
committerEllie Huxtable <e@elm.sh>2021-04-21 21:26:44 +0100
commit4a50ce366639ca9dac7324d6a47d6a0e6c7fccdf (patch)
tree7ffd8848f675e1377f750cc0757768d074a5ac05 /atuin-client/src/sync.rs
parenta9b117aad7e6bd09c7ea188258924dc02855db05 (diff)
Bugfixes, show time ago, perf improvements
Also allow unique listing and more ergonomic cwd usage
Diffstat (limited to 'atuin-client/src/sync.rs')
-rw-r--r--atuin-client/src/sync.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/atuin-client/src/sync.rs b/atuin-client/src/sync.rs
index 0ca8d3a6..5d81a5e6 100644
--- a/atuin-client/src/sync.rs
+++ b/atuin-client/src/sync.rs
@@ -7,7 +7,7 @@ use atuin_common::{api::AddHistoryRequest, utils::hash_str};
use crate::api_client;
use crate::database::Database;
-use crate::encryption::{encrypt, load_key};
+use crate::encryption::{encrypt, load_encoded_key, load_key};
use crate::settings::{Settings, HISTORY_PAGE_SIZE};
// Currently sync is kinda naive, and basically just pages backwards through
@@ -26,6 +26,8 @@ async fn sync_download(
client: &api_client::Client<'_>,
db: &mut (impl Database + Send),
) -> Result<(i64, i64)> {
+ debug!("starting sync download");
+
let remote_count = client.count().await?;
let initial_local = db.history_count()?;
@@ -46,14 +48,14 @@ async fn sync_download(
.get_history(last_sync, last_timestamp, host.clone())
.await?;
- if page.len() < HISTORY_PAGE_SIZE.try_into().unwrap() {
- break;
- }
-
db.save_bulk(&page)?;
local_count = db.history_count()?;
+ if page.len() < HISTORY_PAGE_SIZE.try_into().unwrap() {
+ break;
+ }
+
let page_last = page
.last()
.expect("could not get last element of page")
@@ -80,11 +82,15 @@ async fn sync_upload(
client: &api_client::Client<'_>,
db: &mut (impl Database + Send),
) -> Result<()> {
+ debug!("starting sync upload");
+
let initial_remote_count = client.count().await?;
let mut remote_count = initial_remote_count;
let local_count = db.history_count()?;
+ debug!("remote has {}, we have {}", remote_count, local_count);
+
let key = load_key(settings)?; // encryption key
// first just try the most recent set
@@ -127,8 +133,8 @@ pub async fn sync(settings: &Settings, force: bool, db: &mut (impl Database + Se
let client = api_client::Client::new(
settings.sync_address.as_str(),
settings.session_token.as_str(),
- load_key(settings)?,
- );
+ load_encoded_key(settings)?,
+ )?;
sync_upload(settings, force, &client, db).await?;