aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-client/src
diff options
context:
space:
mode:
author依云 <lilydjwg@gmail.com>2025-04-18 06:21:25 +0800
committerGitHub <noreply@github.com>2025-04-17 23:21:25 +0100
commitd016e2c9be39072b3b0eaa7cb35418e4549c3823 (patch)
treedd3e079890562ae0316f614b96b690083e0a12eb /crates/atuin-client/src
parentUpdate dependencies (#2695) (diff)
downloadatuin-d016e2c9be39072b3b0eaa7cb35418e4549c3823.zip
feat: delete duplicate history (#2697)
Diffstat (limited to 'crates/atuin-client/src')
-rw-r--r--crates/atuin-client/src/database.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/crates/atuin-client/src/database.rs b/crates/atuin-client/src/database.rs
index de362766..06f0bbb8 100644
--- a/crates/atuin-client/src/database.rs
+++ b/crates/atuin-client/src/database.rs
@@ -119,6 +119,8 @@ pub trait Database: Send + Sync + 'static {
async fn all_with_count(&self) -> Result<Vec<(History, i32)>>;
async fn stats(&self, h: &History) -> Result<HistoryStats>;
+
+ async fn get_dups(&self, before: i64, dupkeep: u32) -> Result<Vec<History>>;
}
// Intended for use on a developer machine and not a sync server.
@@ -768,6 +770,26 @@ impl Database for Sqlite {
duration_over_time,
})
}
+
+ async fn get_dups(&self, before: i64, dupkeep: u32) -> Result<Vec<History>> {
+ let res = sqlx::query(
+ "SELECT * FROM (
+ SELECT *, ROW_NUMBER()
+ OVER (PARTITION BY command, cwd, hostname ORDER BY timestamp DESC)
+ AS rn
+ FROM history
+ ) sub
+ WHERE rn > ?1 and timestamp < ?2;
+ ",
+ )
+ .bind(dupkeep)
+ .bind(before)
+ .map(Self::query_history)
+ .fetch_all(&self.pool)
+ .await?;
+
+ Ok(res)
+ }
}
trait SqlBuilderExt {