Browse Source

SearchBackend: add Auto variant as default

jmap-eventsource
Manos Pitsidianakis 2 years ago
parent
commit
fba69d1e5d
Signed by untrusted user: epilys GPG Key ID: 73627C2F690DF710
  1. 8
      src/components/mail/status.rs
  2. 23
      src/conf.rs
  3. 17
      src/conf/accounts.rs

8
src/components/mail/status.rs

@ -370,8 +370,12 @@ impl Component for AccountStatus {
a.settings.conf.search_backend(),
a.backend_capabilities.supports_search,
) {
(SearchBackend::None, true) => "backend-side search".to_string(),
(SearchBackend::None, false) => "none (search will be slow)".to_string(),
(SearchBackend::Auto, true) | (SearchBackend::None, true) => {
"backend-side search".to_string()
}
(SearchBackend::Auto, false) | (SearchBackend::None, false) => {
"none (search will be slow)".to_string()
}
#[cfg(feature = "sqlite3")]
(SearchBackend::Sqlite3, _) => {
if let Ok(path) = crate::sqlite3::db_path() {

23
src/conf.rs

@ -621,23 +621,17 @@ impl Serialize for IndexStyle {
}
}
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum SearchBackend {
None,
Auto,
#[cfg(feature = "sqlite3")]
Sqlite3,
}
impl Default for SearchBackend {
fn default() -> Self {
#[cfg(feature = "sqlite3")]
{
SearchBackend::Sqlite3
}
#[cfg(not(feature = "sqlite3"))]
{
SearchBackend::None
}
SearchBackend::Auto
}
}
@ -649,8 +643,14 @@ impl<'de> Deserialize<'de> for SearchBackend {
let s = <String>::deserialize(deserializer)?;
match s.as_str() {
#[cfg(feature = "sqlite3")]
"sqlite3" => Ok(SearchBackend::Sqlite3),
"nothing" | "none" | "" => Ok(SearchBackend::None),
sqlite3 if sqlite3.eq_ignore_ascii_case("sqlite3") => Ok(SearchBackend::Sqlite3),
none if none.eq_ignore_ascii_case("none")
|| none.eq_ignore_ascii_case("nothing")
|| none.is_empty() =>
{
Ok(SearchBackend::None)
}
auto if auto.eq_ignore_ascii_case("auto") => Ok(SearchBackend::Auto),
_ => Err(de::Error::custom("invalid `search_backend` value")),
}
}
@ -665,6 +665,7 @@ impl Serialize for SearchBackend {
#[cfg(feature = "sqlite3")]
SearchBackend::Sqlite3 => serializer.serialize_str("sqlite3"),
SearchBackend::None => serializer.serialize_str("none"),
SearchBackend::Auto => serializer.serialize_str("auto"),
}
}
}

17
src/conf/accounts.rs

@ -437,8 +437,19 @@ impl Account {
}
};
if ["imap", "jmap", "notmuch"].contains(&settings.account().format()) {
settings.conf.search_backend = crate::conf::SearchBackend::None;
if settings.conf.search_backend == crate::conf::SearchBackend::Auto {
if backend.capabilities().supports_search {
settings.conf.search_backend = crate::conf::SearchBackend::None;
} else {
#[cfg(feature = "sqlite3")]
{
settings.conf.search_backend = crate::conf::SearchBackend::Sqlite3;
}
#[cfg(not(feature = "sqlite3"))]
{
settings.conf.search_backend = crate::conf::SearchBackend::None;
}
}
}
let mut active_jobs = HashMap::default();
@ -1433,7 +1444,7 @@ impl Account {
match self.settings.conf.search_backend {
#[cfg(feature = "sqlite3")]
crate::conf::SearchBackend::Sqlite3 => crate::sqlite3::search(&query, _sort),
crate::conf::SearchBackend::None => {
crate::conf::SearchBackend::Auto | crate::conf::SearchBackend::None => {
if self.backend_capabilities.supports_search {
self.backend
.read()

Loading…
Cancel
Save