From 05de540de7c2eace76b4c3a7941224b7c8ab01fc Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Wed, 3 Jul 2024 07:56:20 +0100 Subject: [PATCH] fix: idx cache inconsistency --- .../atuin-client/src/record/sqlite_store.rs | 19 ++++++++++--------- crates/atuin-server-postgres/src/lib.rs | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/crates/atuin-client/src/record/sqlite_store.rs b/crates/atuin-client/src/record/sqlite_store.rs index 31de311b65f..63ef42f8cd1 100644 --- a/crates/atuin-client/src/record/sqlite_store.rs +++ b/crates/atuin-client/src/record/sqlite_store.rs @@ -219,15 +219,16 @@ impl Store for SqliteStore { idx: RecordIdx, limit: u64, ) -> Result>> { - let res = - sqlx::query("select * from store where idx >= ?1 and host = ?2 and tag = ?3 limit ?4") - .bind(idx as i64) - .bind(host.0.as_hyphenated().to_string()) - .bind(tag) - .bind(limit as i64) - .map(Self::query_row) - .fetch_all(&self.pool) - .await?; + let res = sqlx::query( + "select * from store where idx >= ?1 and host = ?2 and tag = ?3 order by idx asc limit ?4", + ) + .bind(idx as i64) + .bind(host.0.as_hyphenated().to_string()) + .bind(tag) + .bind(limit as i64) + .map(Self::query_row) + .fetch_all(&self.pool) + .await?; Ok(res) } diff --git a/crates/atuin-server-postgres/src/lib.rs b/crates/atuin-server-postgres/src/lib.rs index 6c3572bc38b..47e9486b7a5 100644 --- a/crates/atuin-server-postgres/src/lib.rs +++ b/crates/atuin-server-postgres/src/lib.rs @@ -571,7 +571,7 @@ impl Database for Postgres { "insert into store_idx_cache (user_id, host, tag, idx) values ($1, $2, $3, $4) - on conflict(user_id, host, tag) do update set idx = $4 + on conflict(user_id, host, tag) do update set idx = greatest(idx, $4) ", ) .bind(user.id)