melib/notmuch: cleanup Query new() method
parent
ab0ef1b63c
commit
4f164dc700
|
@ -101,7 +101,7 @@ impl DbConnection {
|
||||||
*self.revision_uuid.read().unwrap(),
|
*self.revision_uuid.read().unwrap(),
|
||||||
new_revision_uuid
|
new_revision_uuid
|
||||||
);
|
);
|
||||||
let query: Query = Query::new(self.lib.clone(), &self, &query_str)?;
|
let query: Query = Query::new(&self, &query_str)?;
|
||||||
let iter = query.search()?;
|
let iter = query.search()?;
|
||||||
let mailbox_index_lck = mailbox_index.write().unwrap();
|
let mailbox_index_lck = mailbox_index.write().unwrap();
|
||||||
let mailboxes_lck = mailboxes.read().unwrap();
|
let mailboxes_lck = mailboxes.read().unwrap();
|
||||||
|
@ -134,7 +134,7 @@ impl DbConnection {
|
||||||
Ok(env) => {
|
Ok(env) => {
|
||||||
for (&mailbox_hash, m) in mailboxes_lck.iter() {
|
for (&mailbox_hash, m) in mailboxes_lck.iter() {
|
||||||
let query_str = format!("{} id:{}", m.query_str.as_str(), &message_id);
|
let query_str = format!("{} id:{}", m.query_str.as_str(), &message_id);
|
||||||
let query: Query = Query::new(self.lib.clone(), self, &query_str)?;
|
let query: Query = Query::new(self, &query_str)?;
|
||||||
if query.count().unwrap_or(0) > 0 {
|
if query.count().unwrap_or(0) > 0 {
|
||||||
let mut total_lck = m.total.lock().unwrap();
|
let mut total_lck = m.total.lock().unwrap();
|
||||||
let mut unseen_lck = m.unseen.lock().unwrap();
|
let mut unseen_lck = m.unseen.lock().unwrap();
|
||||||
|
@ -521,7 +521,7 @@ impl MailBackend for NotmuchDb {
|
||||||
{
|
{
|
||||||
let mailboxes_lck = mailboxes.read().unwrap();
|
let mailboxes_lck = mailboxes.read().unwrap();
|
||||||
let mailbox = mailboxes_lck.get(&mailbox_hash).unwrap();
|
let mailbox = mailboxes_lck.get(&mailbox_hash).unwrap();
|
||||||
let query: Query = Query::new(self.lib.clone(), &database, mailbox.query_str.as_str())?;
|
let query: Query = Query::new(&database, mailbox.query_str.as_str())?;
|
||||||
{
|
{
|
||||||
let mut total_lck = mailbox.total.lock().unwrap();
|
let mut total_lck = mailbox.total.lock().unwrap();
|
||||||
let mut unseen_lck = mailbox.unseen.lock().unwrap();
|
let mut unseen_lck = mailbox.unseen.lock().unwrap();
|
||||||
|
@ -821,7 +821,6 @@ impl MailBackend for NotmuchDb {
|
||||||
self.lib.clone(),
|
self.lib.clone(),
|
||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
let lib = self.lib.clone();
|
|
||||||
let mailboxes = self.mailboxes.clone();
|
let mailboxes = self.mailboxes.clone();
|
||||||
Ok(Box::pin(async move {
|
Ok(Box::pin(async move {
|
||||||
let mut ret = SmallVec::new();
|
let mut ret = SmallVec::new();
|
||||||
|
@ -838,7 +837,7 @@ impl MailBackend for NotmuchDb {
|
||||||
String::new()
|
String::new()
|
||||||
};
|
};
|
||||||
melib_query.query_to_string(&mut query_s);
|
melib_query.query_to_string(&mut query_s);
|
||||||
let query: Query = Query::new(lib.clone(), &database, &query_s)?;
|
let query: Query = Query::new(&database, &query_s)?;
|
||||||
let iter = query.search()?;
|
let iter = query.search()?;
|
||||||
for message in iter {
|
for message in iter {
|
||||||
ret.push(message.env_hash());
|
ret.push(message.env_hash());
|
||||||
|
@ -898,11 +897,8 @@ pub struct Query<'s> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'s> Query<'s> {
|
impl<'s> Query<'s> {
|
||||||
fn new(
|
fn new(database: &DbConnection, query_str: &'s str) -> Result<Self> {
|
||||||
lib: Arc<libloading::Library>,
|
let lib: Arc<libloading::Library> = database.lib.clone();
|
||||||
database: &DbConnection,
|
|
||||||
query_str: &'s str,
|
|
||||||
) -> Result<Self> {
|
|
||||||
let query_cstr = std::ffi::CString::new(query_str)?;
|
let query_cstr = std::ffi::CString::new(query_str)?;
|
||||||
let query: *mut notmuch_query_t = unsafe {
|
let query: *mut notmuch_query_t = unsafe {
|
||||||
call!(lib, notmuch_query_create)(*database.inner.read().unwrap(), query_cstr.as_ptr())
|
call!(lib, notmuch_query_create)(*database.inner.read().unwrap(), query_cstr.as_ptr())
|
||||||
|
|
Loading…
Reference in New Issue