Fix search pagination and add count RPC.

This commit is contained in:
Bill Thiede 2023-11-20 21:18:40 -08:00
parent a7b172099b
commit e6692059b4

View File

@ -40,6 +40,11 @@ struct Tag {
#[Object]
impl QueryRoot {
async fn count<'ctx>(&self, ctx: &Context<'ctx>, query: String) -> Result<usize, Error> {
let nm = ctx.data_unchecked::<Notmuch>();
Ok(nm.count(&query)?)
}
async fn search<'ctx>(
&self,
ctx: &Context<'ctx>,
@ -59,7 +64,7 @@ impl QueryRoot {
info!("{after:?} {before:?} {first:?} {last:?} {query}");
let mut start = 0usize;
let total = nm.count(&query)?;
let mut end = total;
let page_size = first.unwrap_or(20);
if let Some(after) = after {
if after >= total {
@ -67,6 +72,10 @@ impl QueryRoot {
}
start = after + 1;
}
let mut end = start + page_size;
if end > total {
end = total;
}
// TODO(wathiede): handle last/end.
if let Some(before) = before {