ui: Add CacheType option in configuration
CacheType's value dictates which cache backend to use: none, or sqlite3jmap
parent
229e879c26
commit
74672f0807
|
@ -166,6 +166,8 @@ pub struct FileAccount {
|
||||||
read_only: bool,
|
read_only: bool,
|
||||||
subscribed_folders: Vec<String>,
|
subscribed_folders: Vec<String>,
|
||||||
folders: Option<HashMap<String, FolderConf>>,
|
folders: Option<HashMap<String, FolderConf>>,
|
||||||
|
#[serde(default)]
|
||||||
|
cache_type: CacheType,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<FileAccount> for AccountConf {
|
impl From<FileAccount> for AccountConf {
|
||||||
|
@ -268,6 +270,10 @@ impl FileAccount {
|
||||||
pub fn index_style(&self) -> IndexStyle {
|
pub fn index_style(&self) -> IndexStyle {
|
||||||
self.index_style
|
self.index_style
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cache_type(&self) -> &CacheType {
|
||||||
|
&self.cache_type
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||||
|
@ -554,23 +560,50 @@ impl Serialize for IndexStyle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum IndexCache {
|
pub enum CacheType {
|
||||||
Nothing,
|
None,
|
||||||
#[cfg(feature = "sqlite3")]
|
#[cfg(feature = "sqlite3")]
|
||||||
Sqlite3,
|
Sqlite3,
|
||||||
Backend,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for IndexCache {
|
impl Default for CacheType {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
#[cfg(feature = "sqlite3")]
|
#[cfg(feature = "sqlite3")]
|
||||||
{
|
{
|
||||||
IndexCache::Sqlite3
|
CacheType::Sqlite3
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "sqlite3"))]
|
#[cfg(not(feature = "sqlite3"))]
|
||||||
{
|
{
|
||||||
IndexCache::Nothing
|
CacheType::None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for CacheType {
|
||||||
|
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let s = <String>::deserialize(deserializer)?;
|
||||||
|
match s.as_str() {
|
||||||
|
#[cfg(feature = "sqlite3")]
|
||||||
|
"sqlite3" => Ok(CacheType::Sqlite3),
|
||||||
|
"nothing" | "none" | "" => Ok(CacheType::None),
|
||||||
|
_ => Err(de::Error::custom("invalid `index_cache` value")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Serialize for CacheType {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
#[cfg(feature = "sqlite3")]
|
||||||
|
CacheType::Sqlite3 => serializer.serialize_str("sqlite3"),
|
||||||
|
CacheType::None => serializer.serialize_str("none"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ pub fn index(context: &mut crate::state::Context) -> Result<()> {
|
||||||
let mutexes = context
|
let mutexes = context
|
||||||
.accounts
|
.accounts
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|acc| acc.settings.account().format() != "imap")
|
.filter(|acc| *acc.settings.conf.cache_type() == crate::conf::CacheType::Sqlite3)
|
||||||
.map(|acc| (acc.collection.envelopes.clone(), acc.backend.clone()))
|
.map(|acc| (acc.collection.envelopes.clone(), acc.backend.clone()))
|
||||||
.collect::<Vec<(Arc<RwLock<_>>, Arc<_>)>>();
|
.collect::<Vec<(Arc<RwLock<_>>, Arc<_>)>>();
|
||||||
let env_hashes = mutexes
|
let env_hashes = mutexes
|
||||||
|
|
Loading…
Reference in New Issue