diff --git a/notmuch/src/lib.rs b/notmuch/src/lib.rs index 7cf18b5..fe5704a 100644 --- a/notmuch/src/lib.rs +++ b/notmuch/src/lib.rs @@ -465,6 +465,8 @@ pub struct Notmuch { config_path: Option, } +// TODO: rewrite to use tokio::process::Command and make everything async to see if that helps with +// concurrency being more parallel. impl Notmuch { pub fn with_config>(config_path: P) -> Notmuch { Notmuch { diff --git a/server/src/graphql.rs b/server/src/graphql.rs index 1211447..5c84e12 100644 --- a/server/src/graphql.rs +++ b/server/src/graphql.rs @@ -9,6 +9,7 @@ use log::info; use notmuch::Notmuch; use serde::{Deserialize, Serialize}; use sqlx::postgres::PgPool; +use tokio::join; use tracing::instrument; use crate::{config::Config, newsreader, nm, tantivy::TantivyConnection, Query}; @@ -286,6 +287,8 @@ impl QueryRoot { Ok(total) } + // TODO: this function doesn't get parallelism, possibly because notmuch is sync and blocks, + // rewrite that with tokio::process:Command #[instrument(skip_all, fields(query=query))] async fn search<'ctx>( &self, @@ -328,18 +331,17 @@ impl QueryRoot { let query: Query = query.parse()?; info!("newsreader_query {query:?}"); - let newsreader_results = newsreader_search( + let newsreader_fut = newsreader_search( pool, newsreader_after, newsreader_before, first, last, &query, - ) - .await?; - let notmuch_results = - notmuch_search(nm, notmuch_after, notmuch_before, first, last, &query).await?; - let tantivy_results = tantivy_search( + ); + let notmuch_fut = + notmuch_search(nm, notmuch_after, notmuch_before, first, last, &query); + let tantivy_fut = tantivy_search( tantivy, pool, tantivy_after, @@ -347,8 +349,13 @@ impl QueryRoot { first, last, &query, - ) - .await?; + ); + let (newsreader_results, notmuch_results, tantivy_results) = + join!(newsreader_fut, notmuch_fut, tantivy_fut); + + let newsreader_results = newsreader_results?; + let notmuch_results = notmuch_results?; + let tantivy_results = tantivy_results?; info!( "newsreader_results ({}) notmuch_results ({}) tantivy_results ({})", newsreader_results.len(),