diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-13 00:50:54 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-13 00:50:54 +0200 |
| commit | 6723829a3398b3c9dd6dc6ae79124f46000606ee (patch) | |
| tree | a1ec535eddd711a4557e4bcc5b94382c3623504c /crates/turtle/src/atuin_client/history | |
| parent | chore(treewide): Cleanup themes (diff) | |
| download | atuin-6723829a3398b3c9dd6dc6ae79124f46000606ee.zip | |
chore(treewide): Remove `cargo` warnings to 0
There are still the `clippy` warnings, but they are for a future date.
Diffstat (limited to 'crates/turtle/src/atuin_client/history')
| -rw-r--r-- | crates/turtle/src/atuin_client/history/store.rs | 78 |
1 files changed, 38 insertions, 40 deletions
diff --git a/crates/turtle/src/atuin_client/history/store.rs b/crates/turtle/src/atuin_client/history/store.rs index c6e079f3..9c7771cc 100644 --- a/crates/turtle/src/atuin_client/history/store.rs +++ b/crates/turtle/src/atuin_client/history/store.rs @@ -27,12 +27,12 @@ pub(crate) enum HistoryRecord { } impl HistoryRecord { - /// Serialize a history record, returning DecryptedData + /// Serialize a history record, returning `DecryptedData` /// The record will be of a certain type /// We map those like so: /// - /// HistoryRecord::Create -> 0 - /// HistoryRecord::Delete-> 1 + /// `HistoryRecord::Create` -> 0 + /// `HistoryRecord::Delete`-> 1 /// /// This numeric identifier is then written as the first byte to the buffer. For history, we /// append the serialized history right afterwards, to avoid having to handle serialization @@ -47,7 +47,7 @@ impl HistoryRecord { let mut output = vec![]; match self { - HistoryRecord::Create(history) => { + Self::Create(history) => { // 0 -> a history create encode::write_u8(&mut output, 0)?; @@ -55,12 +55,12 @@ impl HistoryRecord { encode::write_bin(&mut output, &bytes.0)?; } - HistoryRecord::Delete(id) => { + Self::Delete(id) => { // 1 -> a history delete encode::write_u8(&mut output, 1)?; encode::write_str(&mut output, id.0.as_str())?; } - }; + } Ok(DecryptedData(output)) } @@ -81,11 +81,11 @@ impl HistoryRecord { 0 => { // not super useful to us atm, but perhaps in the future // written by write_bin above - let _ = decode::read_bin_len(&mut bytes).map_err(error_report)?; + decode::read_bin_len(&mut bytes).map_err(error_report)?; let record = History::deserialize(bytes.remaining_slice(), version)?; - Ok(HistoryRecord::Create(record)) + Ok(Self::Create(record)) } // 1 -> HistoryRecord::Delete @@ -99,7 +99,7 @@ impl HistoryRecord { ); } - Ok(HistoryRecord::Delete(id.to_string().into())) + Ok(Self::Delete(id.to_string().into())) } n => { @@ -111,7 +111,7 @@ impl HistoryRecord { impl HistoryStore { pub(crate) fn new(store: SqliteStore, host_id: HostId, encryption_key: [u8; 32]) -> Self { - HistoryStore { + Self { store, host_id, encryption_key, @@ -182,7 +182,7 @@ impl HistoryStore { } /// Delete a batch of history entries via the record store. - /// Returns the record IDs so the caller can run incremental_build when ready. + /// Returns the record IDs so the caller can run `incremental_build` when ready. pub(crate) async fn delete_entries( &self, entries: impl IntoIterator<Item = History>, @@ -209,7 +209,7 @@ impl HistoryStore { let records = self.store.all_tagged(HISTORY_TAG).await?; let mut ret = Vec::with_capacity(records.len()); - for record in records.into_iter() { + for record in records { let hist = match record.version.as_str() { HISTORY_VERSION_V0 | HISTORY_VERSION => { let version = record.version.clone(); @@ -266,33 +266,28 @@ impl HistoryStore { for id in ids { let record = self.store.get(*id).await; - let record = match record { - Ok(record) => record, - _ => { + if let Ok(record) = record { + if record.tag != HISTORY_TAG { continue; } - }; - if record.tag != HISTORY_TAG { - continue; - } + let version = record.version.clone(); + let decrypted = record.decrypt::<PASETO_V4>(&self.encryption_key)?; + let record = match version.as_str() { + HISTORY_VERSION_V0 | HISTORY_VERSION => { + HistoryRecord::deserialize(&decrypted.data, version.as_str())? + } + version => bail!("unknown history version {version:?}"), + }; - let version = record.version.clone(); - let decrypted = record.decrypt::<PASETO_V4>(&self.encryption_key)?; - let record = match version.as_str() { - HISTORY_VERSION_V0 | HISTORY_VERSION => { - HistoryRecord::deserialize(&decrypted.data, version.as_str())? - } - version => bail!("unknown history version {version:?}"), - }; - - match record { - HistoryRecord::Create(h) => { - // TODO: benchmark CPU time/memory tradeoff of batch commit vs one at a time - database.save(&h).await?; - } - HistoryRecord::Delete(id) => { - database.delete_rows(&[id]).await?; + match record { + HistoryRecord::Create(h) => { + // TODO: benchmark CPU time/memory tradeoff of batch commit vs one at a time + database.save(&h).await?; + } + HistoryRecord::Delete(id) => { + database.delete_rows(&[id]).await?; + } } } } @@ -306,10 +301,13 @@ impl HistoryStore { pub(crate) async fn history_ids(&self) -> Result<HashSet<HistoryId>> { let history = self.history().await?; - let ret = HashSet::from_iter(history.iter().map(|h| match h { - HistoryRecord::Create(h) => h.id.clone(), - HistoryRecord::Delete(id) => id.clone(), - })); + let ret = history + .iter() + .map(|h| match h { + HistoryRecord::Create(h) => h.id.clone(), + HistoryRecord::Delete(id) => id.clone(), + }) + .collect::<HashSet<_>>(); Ok(ret) } @@ -320,7 +318,7 @@ impl HistoryStore { ProgressStyle::with_template("{spinner:.blue} {msg}") .unwrap() .with_key("eta", |state: &ProgressState, w: &mut dyn Write| { - write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap() + write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap(); }) .progress_chars("#>-"), ); |
