aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-client/src/kv.rs
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2023-07-14 20:44:08 +0100
committerGitHub <noreply@github.com>2023-07-14 20:44:08 +0100
commit97e24d0d41bb743833e457de5ba49c5c233eb3b3 (patch)
treef0cfefd9048df83d3029cb0b0d21f1f88813fe2e /atuin-client/src/kv.rs
parentBump semver from 5.7.1 to 5.7.2 in /docs (#1100) (diff)
downloadatuin-97e24d0d41bb743833e457de5ba49c5c233eb3b3.zip
Add new sync (#1093)
* Add record migration * Add database functions for inserting history No real tests yet :( I would like to avoid running postgres lol * Add index handler, use UUIDs not strings * Fix a bunch of tests, remove Option<Uuid> * Add tests, all passing * Working upload sync * Record downloading works * Sync download works * Don't waste requests * Use a page size for uploads, make it variable later * Aaaaaand they're encrypted now too * Add cek * Allow reading tail across hosts * Revert "Allow reading tail across hosts" Not like that This reverts commit 7b0c72e7e050c358172f9b53cbd21b9e44cf4931. * Handle multiple shards properly * format * Format and make clippy happy * use some fancy types (#1098) * use some fancy types * fmt * Goodbye horrible tuple * Update atuin-server-postgres/migrations/20230623070418_records.sql Co-authored-by: Conrad Ludgate <conradludgate@gmail.com> * fmt * Sort tests too because time sucks * fix features --------- Co-authored-by: Conrad Ludgate <conradludgate@gmail.com>
Diffstat (limited to 'atuin-client/src/kv.rs')
-rw-r--r--atuin-client/src/kv.rs22
1 files changed, 12 insertions, 10 deletions
diff --git a/atuin-client/src/kv.rs b/atuin-client/src/kv.rs
index c365a385..30018d63 100644
--- a/atuin-client/src/kv.rs
+++ b/atuin-client/src/kv.rs
@@ -101,10 +101,7 @@ impl KvStore {
let bytes = record.serialize()?;
- let parent = store
- .last(host_id.as_str(), KV_TAG)
- .await?
- .map(|entry| entry.id);
+ let parent = store.tail(host_id, KV_TAG).await?.map(|entry| entry.id);
let record = atuin_common::record::Record::builder()
.host(host_id)
@@ -130,17 +127,22 @@ impl KvStore {
namespace: &str,
key: &str,
) -> Result<Option<KvRecord>> {
- // TODO: don't load this from disk so much
- let host_id = Settings::host_id().expect("failed to get host_id");
-
// Currently, this is O(n). When we have an actual KV store, it can be better
// Just a poc for now!
// iterate records to find the value we want
// start at the end, so we get the most recent version
- let Some(mut record) = store.last(host_id.as_str(), KV_TAG).await? else {
+ let tails = store.tag_tails(KV_TAG).await?;
+
+ if tails.is_empty() {
return Ok(None);
- };
+ }
+
+ // first, decide on a record.
+ // try getting the newest first
+ // we always need a way of deciding the "winner" of a write
+ // TODO(ellie): something better than last-write-wins, what if two write at the same time?
+ let mut record = tails.iter().max_by_key(|r| r.timestamp).unwrap().clone();
loop {
let decrypted = match record.version.as_str() {
@@ -154,7 +156,7 @@ impl KvStore {
}
if let Some(parent) = decrypted.parent {
- record = store.get(parent.as_str()).await?;
+ record = store.get(parent).await?;
} else {
break;
}