server: improve tantivy performance by reusing IndexReader
Also improve a bunch of trace logging
This commit is contained in:
@@ -5,7 +5,7 @@ pub mod newsreader;
|
||||
pub mod nm;
|
||||
pub mod tantivy;
|
||||
|
||||
use std::{collections::HashMap, convert::Infallible, str::FromStr, sync::Arc};
|
||||
use std::{collections::HashMap, convert::Infallible, fmt, str::FromStr, sync::Arc};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use cacher::{Cacher, FilesystemCacher};
|
||||
@@ -612,11 +612,38 @@ pub struct Query {
|
||||
pub uids: Vec<String>,
|
||||
pub remainder: Vec<String>,
|
||||
pub is_notmuch: bool,
|
||||
pub is_newsreader: bool,
|
||||
pub is_tantivy: bool,
|
||||
pub corpus: Option<Corpus>,
|
||||
}
|
||||
|
||||
impl fmt::Display for Query {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
if self.unread_only {
|
||||
write!(f, "is:unread ")?;
|
||||
}
|
||||
for tag in &self.tags {
|
||||
write!(f, "tag:{tag} ")?;
|
||||
}
|
||||
for uid in &self.uids {
|
||||
write!(f, "id:{uid} ")?;
|
||||
}
|
||||
if self.is_notmuch {
|
||||
write!(f, "is:mail ")?;
|
||||
}
|
||||
if self.is_tantivy {
|
||||
write!(f, "is:news ")?;
|
||||
}
|
||||
match self.corpus {
|
||||
Some(c) => write!(f, "corpus:{c:?}")?,
|
||||
_ => (),
|
||||
}
|
||||
for rem in &self.remainder {
|
||||
write!(f, "{rem} ")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Query {
|
||||
// Converts the internal state of Query to something suitable for notmuch queries. Removes and
|
||||
// letterbox specific '<key>:<value' tags
|
||||
@@ -648,7 +675,6 @@ impl FromStr for Query {
|
||||
let mut uids = Vec::new();
|
||||
let mut remainder = Vec::new();
|
||||
let mut is_notmuch = false;
|
||||
let is_newsreader = false;
|
||||
let mut is_tantivy = false;
|
||||
let mut corpus = None;
|
||||
for word in s.split_whitespace() {
|
||||
@@ -682,10 +708,7 @@ impl FromStr for Query {
|
||||
}
|
||||
}
|
||||
// If we don't see any explicit filters for a corpus, flip them all on
|
||||
if corpus.is_none() && !(is_newsreader || is_notmuch || is_tantivy) {
|
||||
// Don't set is_newsreader unless debugging, assume tantivy can handle it.
|
||||
// Explicitely setting corpus:newsreader will by-pass this logic
|
||||
// is_newsreader = true;
|
||||
if corpus.is_none() && !(is_notmuch || is_tantivy) {
|
||||
is_notmuch = true;
|
||||
is_tantivy = true;
|
||||
}
|
||||
@@ -695,7 +718,6 @@ impl FromStr for Query {
|
||||
uids,
|
||||
remainder,
|
||||
is_notmuch,
|
||||
is_newsreader,
|
||||
is_tantivy,
|
||||
corpus,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user