Add reindex command

sql
Manos Pitsidianakis 2019-11-02 12:18:41 +02:00
parent 78eecbb104
commit 0a606a71d1
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 22 additions and 3 deletions

View File

@ -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<dyn MailBackend>,
}
/*
impl Cache {
pub fn build_index(&mut self) {

View File

@ -19,14 +19,16 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
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<str> {
@ -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(

View File

@ -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));
}