Skip to content

Commit 5fe8ae0

Browse files
authored
fix: idx cache inconsistency (#2231)
1 parent c3723aa commit 5fe8ae0

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

crates/atuin-client/src/record/sqlite_store.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,16 @@ impl Store for SqliteStore {
219219
idx: RecordIdx,
220220
limit: u64,
221221
) -> Result<Vec<Record<EncryptedData>>> {
222-
let res =
223-
sqlx::query("select * from store where idx >= ?1 and host = ?2 and tag = ?3 limit ?4")
224-
.bind(idx as i64)
225-
.bind(host.0.as_hyphenated().to_string())
226-
.bind(tag)
227-
.bind(limit as i64)
228-
.map(Self::query_row)
229-
.fetch_all(&self.pool)
230-
.await?;
222+
let res = sqlx::query(
223+
"select * from store where idx >= ?1 and host = ?2 and tag = ?3 order by idx asc limit ?4",
224+
)
225+
.bind(idx as i64)
226+
.bind(host.0.as_hyphenated().to_string())
227+
.bind(tag)
228+
.bind(limit as i64)
229+
.map(Self::query_row)
230+
.fetch_all(&self.pool)
231+
.await?;
231232

232233
Ok(res)
233234
}

crates/atuin-server-postgres/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ impl Database for Postgres {
571571
"insert into store_idx_cache
572572
(user_id, host, tag, idx)
573573
values ($1, $2, $3, $4)
574-
on conflict(user_id, host, tag) do update set idx = $4
574+
on conflict(user_id, host, tag) do update set idx = greatest(idx, $4)
575575
",
576576
)
577577
.bind(user.id)

0 commit comments

Comments
 (0)