diff options
| author | 依云 <lilydjwg@gmail.com> | 2025-04-18 06:21:25 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-17 23:21:25 +0100 |
| commit | d016e2c9be39072b3b0eaa7cb35418e4549c3823 (patch) | |
| tree | dd3e079890562ae0316f614b96b690083e0a12eb /crates/atuin-client/src/database.rs | |
| parent | Update dependencies (#2695) (diff) | |
| download | atuin-d016e2c9be39072b3b0eaa7cb35418e4549c3823.zip | |
feat: delete duplicate history (#2697)
Diffstat (limited to 'crates/atuin-client/src/database.rs')
| -rw-r--r-- | crates/atuin-client/src/database.rs | 22 |
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 { |
