Fix search pagination and add count RPC.
This commit is contained in:
parent
a7b172099b
commit
e6692059b4
@ -40,6 +40,11 @@ struct Tag {
|
|||||||
|
|
||||||
#[Object]
|
#[Object]
|
||||||
impl QueryRoot {
|
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>(
|
async fn search<'ctx>(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Context<'ctx>,
|
ctx: &Context<'ctx>,
|
||||||
@ -59,7 +64,7 @@ impl QueryRoot {
|
|||||||
info!("{after:?} {before:?} {first:?} {last:?} {query}");
|
info!("{after:?} {before:?} {first:?} {last:?} {query}");
|
||||||
let mut start = 0usize;
|
let mut start = 0usize;
|
||||||
let total = nm.count(&query)?;
|
let total = nm.count(&query)?;
|
||||||
let mut end = total;
|
let page_size = first.unwrap_or(20);
|
||||||
|
|
||||||
if let Some(after) = after {
|
if let Some(after) = after {
|
||||||
if after >= total {
|
if after >= total {
|
||||||
@ -67,6 +72,10 @@ impl QueryRoot {
|
|||||||
}
|
}
|
||||||
start = after + 1;
|
start = after + 1;
|
||||||
}
|
}
|
||||||
|
let mut end = start + page_size;
|
||||||
|
if end > total {
|
||||||
|
end = total;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(wathiede): handle last/end.
|
// TODO(wathiede): handle last/end.
|
||||||
if let Some(before) = before {
|
if let Some(before) = before {
|
||||||
@ -95,11 +104,11 @@ impl QueryRoot {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
if let Some(first) = first {
|
if let Some(first) = first {
|
||||||
slice = &slice[..first.min(slice.len())];
|
slice = &slice[..first.min(slice.len())];
|
||||||
end -= first.min(slice.len());
|
end -= first.min(slice.len());
|
||||||
} else if let Some(last) = last {
|
} else if let Some(last) = last {
|
||||||
slice = &slice[slice.len() - last.min(slice.len())..];
|
slice = &slice[slice.len() - last.min(slice.len())..];
|
||||||
start = end - last.min(slice.len());
|
start = end - last.min(slice.len());
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user