mirror of
https://github.com/atuinsh/atuin.git
synced 2024-11-22 16:23:54 +01:00
use sqlite grouping rather than subquery (#181)
This commit is contained in:
parent
d36ff138ab
commit
8d215060a1
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user