Delete all instances of a command (#797)
* Delete all instances of a command Our search command will de-dupe results by default. But... This isn't great for deleting! You don't want to run it over-and-over-and-over until all commands are deleted. Loop the query, and keep on deleting what it returns until they are all gone. * Optimize delete upload It was running a request for every element, on every sync lol Only push a delete if needed Future: push all deletes in one request
This commit is contained in:
parent
d1169aee37
commit
79622cf698
3 changed files with 33 additions and 7 deletions
|
@ -460,6 +460,7 @@ impl Database for Sqlite {
|
||||||
])
|
])
|
||||||
.group_by("command")
|
.group_by("command")
|
||||||
.group_by("exit")
|
.group_by("exit")
|
||||||
|
.and_where("deleted_at is null")
|
||||||
.order_desc("timestamp");
|
.order_desc("timestamp");
|
||||||
|
|
||||||
let query = query.sql().expect("bug in list query. please report");
|
let query = query.sql().expect("bug in list query. please report");
|
||||||
|
|
|
@ -111,6 +111,9 @@ async fn sync_upload(
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
debug!("starting sync upload");
|
debug!("starting sync upload");
|
||||||
|
|
||||||
|
let remote_status = client.status().await?;
|
||||||
|
let remote_deleted: HashSet<String> = HashSet::from_iter(remote_status.deleted.clone());
|
||||||
|
|
||||||
let initial_remote_count = client.count().await?;
|
let initial_remote_count = client.count().await?;
|
||||||
let mut remote_count = initial_remote_count;
|
let mut remote_count = initial_remote_count;
|
||||||
|
|
||||||
|
@ -157,6 +160,10 @@ async fn sync_upload(
|
||||||
let deleted = db.deleted().await?;
|
let deleted = db.deleted().await?;
|
||||||
|
|
||||||
for i in deleted {
|
for i in deleted {
|
||||||
|
if remote_deleted.contains(&i.id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
info!("deleting {} on remote", i.id);
|
info!("deleting {} on remote", i.id);
|
||||||
client.delete_history(i).await?;
|
client.delete_history(i).await?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,14 +102,15 @@ impl Cmd {
|
||||||
eprintln!("{item}");
|
eprintln!("{item}");
|
||||||
} else {
|
} else {
|
||||||
let list_mode = ListMode::from_flags(self.human, self.cmd_only);
|
let list_mode = ListMode::from_flags(self.human, self.cmd_only);
|
||||||
let entries = run_non_interactive(
|
|
||||||
|
let mut entries = run_non_interactive(
|
||||||
settings,
|
settings,
|
||||||
self.cwd,
|
self.cwd.clone(),
|
||||||
self.exit,
|
self.exit,
|
||||||
self.exclude_exit,
|
self.exclude_exit,
|
||||||
self.exclude_cwd,
|
self.exclude_cwd.clone(),
|
||||||
self.before,
|
self.before.clone(),
|
||||||
self.after,
|
self.after.clone(),
|
||||||
self.limit,
|
self.limit,
|
||||||
&self.query,
|
&self.query,
|
||||||
db,
|
db,
|
||||||
|
@ -125,8 +126,25 @@ impl Cmd {
|
||||||
// delete it
|
// delete it
|
||||||
// it only took me _years_ to add this
|
// it only took me _years_ to add this
|
||||||
// sorry
|
// sorry
|
||||||
for entry in entries {
|
while !entries.is_empty() {
|
||||||
db.delete(entry).await?;
|
for entry in &entries {
|
||||||
|
eprintln!("deleting {}", entry.id);
|
||||||
|
db.delete(entry.clone()).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
entries = run_non_interactive(
|
||||||
|
settings,
|
||||||
|
self.cwd.clone(),
|
||||||
|
self.exit,
|
||||||
|
self.exclude_exit,
|
||||||
|
self.exclude_cwd.clone(),
|
||||||
|
self.before.clone(),
|
||||||
|
self.after.clone(),
|
||||||
|
self.limit,
|
||||||
|
&self.query,
|
||||||
|
db,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
super::history::print_list(&entries, list_mode, self.format.as_deref());
|
super::history::print_list(&entries, list_mode, self.format.as_deref());
|
||||||
|
|
Loading…
Reference in a new issue