diff --git a/server/src/graphql.rs b/server/src/graphql.rs index 8f89093..5e6c496 100644 --- a/server/src/graphql.rs +++ b/server/src/graphql.rs @@ -217,7 +217,10 @@ impl QueryRoot { let newsreader_query: Query = query.parse()?; - Ok(newsreader::count(pool, &newsreader_query).await? + nm::count(nm, &query).await?) + let newsreader_count = newsreader::count(pool, &newsreader_query).await?; + let notmuch_count = nm::count(nm, &newsreader_query.to_notmuch()).await?; + info!("count {newsreader_query:?} newsreader count {newsreader_count} notmuch count {notmuch_count}"); + Ok(newsreader_count + notmuch_count) } async fn search<'ctx>( diff --git a/server/src/newsreader.rs b/server/src/newsreader.rs index 06fad43..404c60a 100644 --- a/server/src/newsreader.rs +++ b/server/src/newsreader.rs @@ -37,6 +37,12 @@ pub fn make_news_tag(tag: &str) -> String { } pub async fn count(pool: &PgPool, query: &Query) -> Result { + if !query.remainder.is_empty() { + // TODO: handle full text search against all sites, for now, early return if search words + // are specified. + return Ok(0); + } + let row = sqlx::query_file!("sql/count.sql", query.tag, query.unread_only) .fetch_one(pool) .await?; diff --git a/server/src/nm.rs b/server/src/nm.rs index 5b36390..7327a57 100644 --- a/server/src/nm.rs +++ b/server/src/nm.rs @@ -50,7 +50,13 @@ pub async fn search( last: Option, query: String, ) -> Result, async_graphql::Error> { - let (offset, limit) = compute_offset_limit(after, before, first, last); + 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; + } Ok(nm .search(&query, offset as usize, limit as usize)? .0