server: fix backward pagination
This commit is contained in:
parent
f7df834325
commit
24414b04bb
@ -17,7 +17,7 @@ log = "0.4.17"
|
||||
tokio = "1.26.0"
|
||||
glog = "0.1.0"
|
||||
urlencoding = "2.1.3"
|
||||
async-graphql = "6.0.11"
|
||||
async-graphql = { version = "6.0.11", features = ["log"] }
|
||||
async-graphql-rocket = "6.0.11"
|
||||
rocket_cors = "0.6.0"
|
||||
rayon = "1.8.0"
|
||||
|
||||
@ -167,6 +167,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let schema = Schema::build(QueryRoot, EmptyMutation, EmptySubscription)
|
||||
.data(Notmuch::default())
|
||||
.extension(async_graphql::extensions::Logger)
|
||||
.finish();
|
||||
|
||||
let _ = rocket::build()
|
||||
|
||||
@ -64,31 +64,20 @@ impl QueryRoot {
|
||||
last,
|
||||
|after, before, first, last| async move {
|
||||
info!("{after:?} {before:?} {first:?} {last:?} {query}");
|
||||
let mut start = 0usize;
|
||||
let total = nm.count(&query)?;
|
||||
let page_size = first.unwrap_or(20);
|
||||
|
||||
if let Some(after) = after {
|
||||
if after >= total {
|
||||
return Ok(Connection::new(false, false));
|
||||
let mut start = after.map(|after| after + 1).unwrap_or(0);
|
||||
let mut end = before.unwrap_or(total);
|
||||
if let Some(first) = first {
|
||||
end = (start + first).min(end);
|
||||
}
|
||||
start = after + 1;
|
||||
}
|
||||
let mut end = start + page_size;
|
||||
if end > total {
|
||||
end = total;
|
||||
}
|
||||
|
||||
// TODO(wathiede): handle last/end.
|
||||
if let Some(before) = before {
|
||||
if before == 0 {
|
||||
return Ok(Connection::new(false, false));
|
||||
}
|
||||
end = before;
|
||||
if let Some(last) = last {
|
||||
start = if last > end - start { end } else { end - last };
|
||||
}
|
||||
|
||||
let count = end - start;
|
||||
let slice: Vec<ThreadSummary> = nm
|
||||
.search(&query, start, first.unwrap_or(20))?
|
||||
.search(&query, start, count)?
|
||||
.0
|
||||
.into_iter()
|
||||
.map(|ts| ThreadSummary {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user