aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@atuin.sh>2025-07-24 10:08:20 +0200
committerGitHub <noreply@github.com>2025-07-24 10:08:20 +0200
commit0f381dd5152e60bf5473955e9a503a466e50219f (patch)
treec3173e1931d4bac8e4ffb339c914e01420171c18
parentfeat: add inline_height_shell_up_key_binding option (#2817) (diff)
downloadatuin-0f381dd5152e60bf5473955e9a503a466e50219f.zip
fix: use transaction for idx consistency checking (#2840)
-rw-r--r--crates/atuin-server-postgres/src/lib.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/crates/atuin-server-postgres/src/lib.rs b/crates/atuin-server-postgres/src/lib.rs
index 65e8efbf..f399945e 100644
--- a/crates/atuin-server-postgres/src/lib.rs
+++ b/crates/atuin-server-postgres/src/lib.rs
@@ -620,9 +620,12 @@ impl Database for Postgres {
const STATUS_SQL: &str =
"select host, tag, max(idx) from store where user_id = $1 group by host, tag";
+ // Use a transaction to ensure consistent reads from both tables
+ let mut tx = self.pool.begin().await.map_err(fix_error)?;
+
let mut res: Vec<(Uuid, String, i64)> = sqlx::query_as(STATUS_SQL)
.bind(user.id)
- .fetch_all(&self.pool)
+ .fetch_all(&mut *tx)
.await
.map_err(fix_error)?;
res.sort();
@@ -636,11 +639,13 @@ impl Database for Postgres {
let mut cached_res: Vec<(Uuid, String, i64)> =
sqlx::query_as("select host, tag, idx from store_idx_cache where user_id = $1")
.bind(user.id)
- .fetch_all(&self.pool)
+ .fetch_all(&mut *tx)
.await
.map_err(fix_error)?;
cached_res.sort();
+ tx.commit().await.map_err(fix_error)?;
+
let mut status = RecordStatus::new();
let equal = res == cached_res;