server: fix paging bug where p1->p2->p1 wouldn't show consistent results

This commit is contained in:
2024-08-06 21:15:10 -07:00
parent 474cf38180
commit 7c5ef96ff0
3 changed files with 9 additions and 12 deletions

View File

@@ -43,9 +43,13 @@ pub async fn search(
query: &Query,
) -> Result<Vec<(i32, ThreadSummary)>, async_graphql::Error> {
info!("search({after:?} {before:?} {first:?} {last:?} {query:?}");
let (offset, limit) = compute_offset_limit(after, before, first, last);
// The +1 is to see if there are more pages of data available.
let limit = limit + 1;
let (offset, mut limit) = compute_offset_limit(after, before, first, last);
if before.is_none() {
// When searching forward, the +1 is to see if there are more pages of data available.
// Searching backwards implies there's more pages forward, because the value represented by
// `before` is on the next page.
limit = limit + 1;
}
info!("search offset {offset} limit {limit}");
let rows = sqlx::query_file!(