Skip to content

Commit

Permalink
Improve history isolation
Browse files Browse the repository at this point in the history
After this change we will get rows:
- that have the same session_id, or
- have a lower id than the first command with our session_id, or
- if there's no command with our session_id, take the whole history.
  • Loading branch information
Hofer-Julian committed Sep 10, 2023
1 parent 409b517 commit 3cb5f7e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/history/sqlite_backed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,15 @@ impl SqliteBackedHistory {
}
}
if let Some(session_id) = query.filter.session {
wheres.push("session_id = :session_id");
// Filter so that we get rows:
// - that have the same session_id, or
// - have a lower id than the first command with our session_id, or
// - if there's no command with our session_id, take the whole history.
wheres.push(
"(session_id = :session_id OR \
id < (SELECT MIN(id) FROM history WHERE session_id = :session_id) OR \
COALESCE((SELECT MIN(id) FROM history WHERE session_id = :session_id), -1) = -1)",
);
params.push((":session_id", Box::new(session_id)));
}
let mut wheres = wheres.join(" and ");
Expand Down

0 comments on commit 3cb5f7e

Please sign in to comment.