aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-client/src/database.rs
diff options
context:
space:
mode:
authorMark Wotton <mwotton@gmail.com>2021-12-19 17:29:01 +0700
committerGitHub <noreply@github.com>2021-12-19 10:29:01 +0000
commit8d215060a1f61cde2f9d1a5ed83dabfce86dda55 (patch)
tree4016eae9a9b0e1b1c9dedfc1b7e3348ba9009262 /atuin-client/src/database.rs
parentReplace dpkg with apt (#248) (diff)
downloadatuin-8d215060a1f61cde2f9d1a5ed83dabfce86dda55.zip
use sqlite grouping rather than subquery (#181)
Diffstat (limited to 'atuin-client/src/database.rs')
-rw-r--r--atuin-client/src/database.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs
index 8dff15fd..5e897cc0 100644
--- a/atuin-client/src/database.rs
+++ b/atuin-client/src/database.rs
@@ -296,10 +296,8 @@ impl Database for Sqlite {
format!(
"select * from history h
where command like ?1 || '%'
- and timestamp = (
- select max(timestamp) from history
- where h.command = history.command
- )
+ group by command
+ having max(timestamp)
order by timestamp desc {}",
limit.clone()
)
@@ -326,6 +324,7 @@ impl Database for Sqlite {
#[cfg(test)]
mod test {
use super::*;
+ use std::time::{Duration, Instant};
async fn new_history_item(db: &mut impl Database, cmd: &str) -> Result<()> {
let history = History::new(
@@ -427,4 +426,19 @@ mod test {
results = db.search(None, SearchMode::Fuzzy, "").await.unwrap();
assert_eq!(results.len(), 2);
}
+
+ #[tokio::test(flavor = "multi_thread")]
+ async fn test_search_bench_dupes() {
+ let mut db = Sqlite::new("sqlite::memory:").await.unwrap();
+ for _i in 1..10000 {
+ new_history_item(&mut db, "i am a duplicated command")
+ .await
+ .unwrap();
+ }
+ let start = Instant::now();
+ let _results = db.search(None, SearchMode::Fuzzy, "").await.unwrap();
+ let duration = start.elapsed();
+
+ assert!(duration < Duration::from_secs(15));
+ }
}