Browse Source

ui: Add CacheType option in configuration

CacheType's value dictates which cache backend to use: none, or sqlite3
tags/pre-alpha-0.4.0
Manos Pitsidianakis 3 months ago
parent
commit
74672f0807
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS. GPG Key ID: 73627C2F690DF710
2 changed files with 41 additions and 8 deletions
  1. +40
    -7
      ui/src/conf.rs
  2. +1
    -1
      ui/src/sqlite3.rs

+ 40
- 7
ui/src/conf.rs View File

@@ -166,6 +166,8 @@ pub struct FileAccount {
read_only: bool,
subscribed_folders: Vec<String>,
folders: Option<HashMap<String, FolderConf>>,
#[serde(default)]
cache_type: CacheType,
}

impl From<FileAccount> for AccountConf {
@@ -268,6 +270,10 @@ impl FileAccount {
pub fn index_style(&self) -> IndexStyle {
self.index_style
}

pub fn cache_type(&self) -> &CacheType {
&self.cache_type
}
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
@@ -554,23 +560,50 @@ impl Serialize for IndexStyle {
}
}

#[derive(Debug)]
pub enum IndexCache {
Nothing,
#[derive(Debug, Clone, PartialEq)]
pub enum CacheType {
None,
#[cfg(feature = "sqlite3")]
Sqlite3,
Backend,
}

impl Default for IndexCache {
impl Default for CacheType {
fn default() -> Self {
#[cfg(feature = "sqlite3")]
{
IndexCache::Sqlite3
CacheType::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"),
}
}
}

+ 1
- 1
ui/src/sqlite3.rs View File

@@ -198,7 +198,7 @@ pub fn index(context: &mut crate::state::Context) -> Result<()> {
let mutexes = context
.accounts
.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()))
.collect::<Vec<(Arc<RwLock<_>>, Arc<_>)>>();
let env_hashes = mutexes


Loading…
Cancel
Save