mirror of
https://github.com/atuinsh/atuin.git
synced 2025-06-20 18:07:57 +02:00
feat: make deleting from the UI work with record store sync (#1580)
* feat: make deleting from the UI work with record store sync * sort cli delete too * teeny bit more logs
This commit is contained in:
parent
ef38fd0a29
commit
d9317a1a9c
@ -286,6 +286,8 @@ impl<'a> Client<'a> {
|
|||||||
let url = format!("{}/api/v0/record", self.sync_addr);
|
let url = format!("{}/api/v0/record", self.sync_addr);
|
||||||
let url = Url::parse(url.as_str())?;
|
let url = Url::parse(url.as_str())?;
|
||||||
|
|
||||||
|
debug!("uploading {} records to {url}", records.len());
|
||||||
|
|
||||||
let resp = self.client.post(url).json(records).send().await?;
|
let resp = self.client.post(url).json(records).send().await?;
|
||||||
handle_resp_error(resp).await?;
|
handle_resp_error(resp).await?;
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ impl HistoryStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn push_record(&self, record: HistoryRecord) -> Result<RecordIdx> {
|
async fn push_record(&self, record: HistoryRecord) -> Result<(RecordId, RecordIdx)> {
|
||||||
let bytes = record.serialize()?;
|
let bytes = record.serialize()?;
|
||||||
let idx = self
|
let idx = self
|
||||||
.store
|
.store
|
||||||
@ -130,20 +130,22 @@ impl HistoryStore {
|
|||||||
.data(bytes)
|
.data(bytes)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
let id = record.id;
|
||||||
|
|
||||||
self.store
|
self.store
|
||||||
.push(&record.encrypt::<PASETO_V4>(&self.encryption_key))
|
.push(&record.encrypt::<PASETO_V4>(&self.encryption_key))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(idx)
|
Ok((id, idx))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete(&self, id: HistoryId) -> Result<RecordIdx> {
|
pub async fn delete(&self, id: HistoryId) -> Result<(RecordId, RecordIdx)> {
|
||||||
let record = HistoryRecord::Delete(id);
|
let record = HistoryRecord::Delete(id);
|
||||||
|
|
||||||
self.push_record(record).await
|
self.push_record(record).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn push(&self, history: History) -> Result<RecordIdx> {
|
pub async fn push(&self, history: History) -> Result<(RecordId, RecordIdx)> {
|
||||||
// TODO(ellie): move the history store to its own file
|
// TODO(ellie): move the history store to its own file
|
||||||
// it's tiny rn so fine as is
|
// it's tiny rn so fine as is
|
||||||
let record = HistoryRecord::Create(history);
|
let record = HistoryRecord::Create(history);
|
||||||
|
@ -89,7 +89,7 @@ impl Cmd {
|
|||||||
Self::History(history) => history.run(&settings, &db, sqlite_store).await,
|
Self::History(history) => history.run(&settings, &db, sqlite_store).await,
|
||||||
Self::Import(import) => import.run(&db).await,
|
Self::Import(import) => import.run(&db).await,
|
||||||
Self::Stats(stats) => stats.run(&db, &settings).await,
|
Self::Stats(stats) => stats.run(&db, &settings).await,
|
||||||
Self::Search(search) => search.run(db, &mut settings).await,
|
Self::Search(search) => search.run(db, &mut settings, sqlite_store).await,
|
||||||
|
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
Self::Sync(sync) => sync.run(settings, &db, sqlite_store).await,
|
Self::Sync(sync) => sync.run(settings, &db, sqlite_store).await,
|
||||||
|
@ -5,7 +5,9 @@ use eyre::Result;
|
|||||||
use atuin_client::{
|
use atuin_client::{
|
||||||
database::Database,
|
database::Database,
|
||||||
database::{current_context, OptFilters},
|
database::{current_context, OptFilters},
|
||||||
history::History,
|
encryption,
|
||||||
|
history::{store::HistoryStore, History},
|
||||||
|
record::sqlite_store::SqliteStore,
|
||||||
settings::{FilterMode, KeymapMode, SearchMode, Settings},
|
settings::{FilterMode, KeymapMode, SearchMode, Settings},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -109,7 +111,12 @@ pub struct Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Cmd {
|
impl Cmd {
|
||||||
pub async fn run(self, db: impl Database, settings: &mut Settings) -> Result<()> {
|
pub async fn run(
|
||||||
|
self,
|
||||||
|
db: impl Database,
|
||||||
|
settings: &mut Settings,
|
||||||
|
store: SqliteStore,
|
||||||
|
) -> Result<()> {
|
||||||
if (self.delete_it_all || self.delete) && self.limit.is_some() {
|
if (self.delete_it_all || self.delete) && self.limit.is_some() {
|
||||||
// Because of how deletion is implemented, it will always delete all matches
|
// Because of how deletion is implemented, it will always delete all matches
|
||||||
// and disregard the limit option. It is also not clear what deletion with a
|
// and disregard the limit option. It is also not clear what deletion with a
|
||||||
@ -153,8 +160,13 @@ impl Cmd {
|
|||||||
value => value,
|
value => value,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let encryption_key: [u8; 32] = encryption::load_key(settings)?.into();
|
||||||
|
|
||||||
|
let host_id = Settings::host_id().expect("failed to get host_id");
|
||||||
|
let history_store = HistoryStore::new(store.clone(), host_id, encryption_key);
|
||||||
|
|
||||||
if self.interactive {
|
if self.interactive {
|
||||||
let item = interactive::history(&self.query, settings, db).await?;
|
let item = interactive::history(&self.query, settings, db, &history_store).await?;
|
||||||
eprintln!("{}", item.escape_control());
|
eprintln!("{}", item.escape_control());
|
||||||
} else {
|
} else {
|
||||||
let list_mode = ListMode::from_flags(self.human, self.cmd_only);
|
let list_mode = ListMode::from_flags(self.human, self.cmd_only);
|
||||||
@ -186,7 +198,13 @@ impl Cmd {
|
|||||||
while !entries.is_empty() {
|
while !entries.is_empty() {
|
||||||
for entry in &entries {
|
for entry in &entries {
|
||||||
eprintln!("deleting {}", entry.id);
|
eprintln!("deleting {}", entry.id);
|
||||||
db.delete(entry.clone()).await?;
|
|
||||||
|
if settings.sync.records {
|
||||||
|
let (id, _) = history_store.delete(entry.id.clone()).await?;
|
||||||
|
history_store.incremental_build(&db, &[id]).await?;
|
||||||
|
} else {
|
||||||
|
db.delete(entry.clone()).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entries =
|
entries =
|
||||||
|
@ -20,7 +20,7 @@ use unicode_width::UnicodeWidthStr;
|
|||||||
|
|
||||||
use atuin_client::{
|
use atuin_client::{
|
||||||
database::{current_context, Database},
|
database::{current_context, Database},
|
||||||
history::{History, HistoryStats},
|
history::{store::HistoryStore, History, HistoryStats},
|
||||||
settings::{ExitMode, FilterMode, KeymapMode, SearchMode, Settings},
|
settings::{ExitMode, FilterMode, KeymapMode, SearchMode, Settings},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -769,6 +769,7 @@ pub async fn history(
|
|||||||
query: &[String],
|
query: &[String],
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
mut db: impl Database,
|
mut db: impl Database,
|
||||||
|
history_store: &HistoryStore,
|
||||||
) -> Result<String> {
|
) -> Result<String> {
|
||||||
let stdout = Stdout::new(settings.inline_height > 0)?;
|
let stdout = Stdout::new(settings.inline_height > 0)?;
|
||||||
let backend = CrosstermBackend::new(stdout);
|
let backend = CrosstermBackend::new(stdout);
|
||||||
@ -857,7 +858,13 @@ pub async fn history(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let entry = results.remove(index);
|
let entry = results.remove(index);
|
||||||
db.delete(entry).await?;
|
|
||||||
|
if settings.sync.records {
|
||||||
|
let (id, _) = history_store.delete(entry.id).await?;
|
||||||
|
history_store.incremental_build(&db, &[id]).await?;
|
||||||
|
} else {
|
||||||
|
db.delete(entry.clone()).await?;
|
||||||
|
}
|
||||||
|
|
||||||
app.tab_index = 0;
|
app.tab_index = 0;
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user