From 0a606a71d16f8782d17946e6f225b74a2eea58b2 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 2 Nov 2019 12:18:41 +0200 Subject: [PATCH] Add reindex command --- ui/src/cache.rs | 2 ++ ui/src/sqlite3.rs | 6 ++++-- ui/src/state.rs | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ui/src/cache.rs b/ui/src/cache.rs index 22c8f33ee..0f2f6878d 100644 --- a/ui/src/cache.rs +++ b/ui/src/cache.rs @@ -23,6 +23,7 @@ use melib::backends::{FolderHash, MailBackend}; use melib::email::{EnvelopeHash, Flag, UnixTimestamp}; use melib::mailbox::*; use melib::thread::{ThreadHash, ThreadNode}; +use std::sync::RwLock; #[derive(Debug)] pub enum Query { @@ -56,6 +57,7 @@ pub struct Cache { kind: CacheType, backend: Box, } +/* impl Cache { pub fn build_index(&mut self) { diff --git a/ui/src/sqlite3.rs b/ui/src/sqlite3.rs index adfb49a05..3324d5e09 100644 --- a/ui/src/sqlite3.rs +++ b/ui/src/sqlite3.rs @@ -19,14 +19,16 @@ * along with meli. If not, see . */ +use fnv::FnvHashMap; use melib::{ - email::EnvelopeHash, + email::{Envelope, EnvelopeHash}, thread::{SortField, SortOrder}, MeliError, Result, StackVec, }; use rusqlite::{params, Connection}; use std::borrow::Cow; use std::convert::TryInto; +use std::sync::{Arc, RwLock}; #[inline(always)] fn escape_double_quote(w: &str) -> Cow { @@ -160,7 +162,7 @@ END; ", Ok(conn) } -pub fn insert(context: &crate::state::Context) -> Result<()> { +pub fn insert(context: &mut crate::state::Context) -> Result<()> { let data_dir = xdg::BaseDirectories::with_prefix("meli").map_err(|e| MeliError::new(e.to_string()))?; let conn = Connection::open( diff --git a/ui/src/state.rs b/ui/src/state.rs index f83ef65fd..c30fd7e12 100644 --- a/ui/src/state.rs +++ b/ui/src/state.rs @@ -530,7 +530,6 @@ impl State { /// Convert user commands to actions/method calls. fn parse_command(&mut self, cmd: &str) { if cmd == "insert" { - crate::sqlite3::insert(&self.context).unwrap(); return; } else if cmd.starts_with("_from") { debug!(crate::sqlite3::from(&cmd["_from".len()..])); @@ -572,6 +571,22 @@ impl State { )); } } + AccountAction(_, ReIndex) => match crate::sqlite3::insert(&mut self.context) { + Ok(()) => { + self.context.replies.push_back(UIEvent::Notification( + None, + "Message index rebuild started.".to_string(), + Some(NotificationType::INFO), + )); + } + Err(e) => { + self.context.replies.push_back(UIEvent::Notification( + None, + format!("Message index rebuild failed: {}.", e), + Some(NotificationType::ERROR), + )); + } + }, v => { self.rcv_event(UIEvent::Action(v)); }