8000 use sqlite grouping rather than subquery by mwotton · Pull Request #181 · atuinsh/atuin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

use sqlite grouping rather than subquery #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions atuin-client/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand All @@ -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(
Expand Down Expand Up @@ -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));
}
}
0