mirror of
https://github.com/atuinsh/atuin.git
synced 2025-02-01 11:09:44 +01:00
feat: add automatic history store init (#1831)
This commit is contained in:
parent
be6f6534da
commit
da24f734e5
@ -5,7 +5,7 @@ use indicatif::{ProgressBar, ProgressState, ProgressStyle};
|
|||||||
use rmp::decode::Bytes;
|
use rmp::decode::Bytes;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
database::{self, Database},
|
database::{current_context, Database},
|
||||||
record::{encryption::PASETO_V4, sqlite_store::SqliteStore, store::Store},
|
record::{encryption::PASETO_V4, sqlite_store::SqliteStore, store::Store},
|
||||||
};
|
};
|
||||||
use atuin_common::record::{DecryptedData, Host, HostId, Record, RecordId, RecordIdx};
|
use atuin_common::record::{DecryptedData, Host, HostId, Record, RecordId, RecordIdx};
|
||||||
@ -287,7 +287,7 @@ impl HistoryStore {
|
|||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn init_store(&self, context: database::Context, db: &impl Database) -> Result<()> {
|
pub async fn init_store(&self, db: &impl Database) -> Result<()> {
|
||||||
let pb = ProgressBar::new_spinner();
|
let pb = ProgressBar::new_spinner();
|
||||||
pb.set_style(
|
pb.set_style(
|
||||||
ProgressStyle::with_template("{spinner:.blue} {msg}")
|
ProgressStyle::with_template("{spinner:.blue} {msg}")
|
||||||
@ -300,6 +300,8 @@ impl HistoryStore {
|
|||||||
pb.enable_steady_tick(Duration::from_millis(500));
|
pb.enable_steady_tick(Duration::from_millis(500));
|
||||||
|
|
||||||
pb.set_message("Fetching history from old database");
|
pb.set_message("Fetching history from old database");
|
||||||
|
|
||||||
|
let context = current_context();
|
||||||
let history = db.list(&[], &context, None, false, true).await?;
|
let history = db.list(&[], &context, None, false, true).await?;
|
||||||
|
|
||||||
pb.set_message("Fetching history already in store");
|
pb.set_message("Fetching history already in store");
|
||||||
|
@ -475,11 +475,6 @@ impl Cmd {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn init_store(&self, db: &impl Database, history_store: HistoryStore) -> Result<()> {
|
|
||||||
let context = current_context();
|
|
||||||
history_store.init_store(context, db).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn run(
|
pub async fn run(
|
||||||
self,
|
self,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
@ -542,7 +537,7 @@ impl Cmd {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
Self::InitStore => self.init_store(db, history_store).await,
|
Self::InitStore => history_store.init_store(db).await,
|
||||||
|
|
||||||
Self::Prune { dry_run } => {
|
Self::Prune { dry_run } => {
|
||||||
Self::handle_prune(db, settings, store, context, dry_run).await
|
Self::handle_prune(db, settings, store, context, dry_run).await
|
||||||
|
@ -99,11 +99,13 @@ async fn run(
|
|||||||
|
|
||||||
#[allow(clippy::cast_sign_loss)]
|
#[allow(clippy::cast_sign_loss)]
|
||||||
if history_length as u64 > store_history_length {
|
if history_length as u64 > store_history_length {
|
||||||
println!("History DB is longer than history record store");
|
println!(
|
||||||
println!("This happens when you used Atuin pre-record-store");
|
"{history_length} in history index, but {store_history_length} in history store"
|
||||||
println!("Run atuin history init-store to correct this");
|
);
|
||||||
|
println!("Running automatic history store init...");
|
||||||
|
|
||||||
println!("\n");
|
// Internally we use the global filter mode, so this context is ignored.
|
||||||
|
history_store.init_store(db).await?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
atuin_client::sync::sync(settings, force, db).await?;
|
atuin_client::sync::sync(settings, force, db).await?;
|
||||||
|
Loading…
Reference in New Issue
Block a user