mu: write contacts-cache a bit sooner
Write the changes to the cache file after any indexing operation, so `mu cfind` gets new contacts a bit sooner.
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
||||||
/*
|
/*
|
||||||
** Copyright (C) 2008-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2008-2016 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify it
|
** This program is free software; you can redistribute it and/or modify it
|
||||||
** under the terms of the GNU General Public License as published by the
|
** under the terms of the GNU General Public License as published by the
|
||||||
@ -280,8 +280,6 @@ clear_str (char* str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mu_contacts_add (MuContacts *self, const char *addr, const char *name,
|
mu_contacts_add (MuContacts *self, const char *addr, const char *name,
|
||||||
gboolean personal, time_t tstamp)
|
gboolean personal, time_t tstamp)
|
||||||
@ -304,7 +302,7 @@ mu_contacts_add (MuContacts *self, const char *addr, const char *name,
|
|||||||
tstamp, 1);
|
tstamp, 1);
|
||||||
g_hash_table_insert (self->_hash, g_strdup(group), cinfo);
|
g_hash_table_insert (self->_hash, g_strdup(group), cinfo);
|
||||||
} else {
|
} else {
|
||||||
/* if the contact is ever user in a personal way, it's
|
/* if the contact is ever used in a personal way, it's
|
||||||
* personal */
|
* personal */
|
||||||
if (personal)
|
if (personal)
|
||||||
cinfo->_personal = TRUE;
|
cinfo->_personal = TRUE;
|
||||||
@ -421,13 +419,15 @@ each_keyval (const char *group, ContactInfo *cinfo, MuContacts *self)
|
|||||||
(int)cinfo->_freq);
|
(int)cinfo->_freq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
gboolean
|
||||||
serialize_cache (MuContacts *self)
|
mu_contacts_serialize (MuContacts *self)
|
||||||
{
|
{
|
||||||
gchar *data;
|
gchar *data;
|
||||||
gsize len;
|
gsize len;
|
||||||
gboolean rv;
|
gboolean rv;
|
||||||
|
|
||||||
|
g_return_val_if_fail (self, FALSE);
|
||||||
|
|
||||||
g_hash_table_foreach (self->_hash, (GHFunc)each_keyval, self);
|
g_hash_table_foreach (self->_hash, (GHFunc)each_keyval, self);
|
||||||
|
|
||||||
/* Note: err arg is unused */
|
/* Note: err arg is unused */
|
||||||
@ -454,11 +454,10 @@ mu_contacts_destroy (MuContacts *self)
|
|||||||
if (!self)
|
if (!self)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (self->_ccache && self->_dirty) {
|
if (self->_ccache && self->_dirty &&
|
||||||
serialize_cache (self);
|
mu_contacts_serialize (self))
|
||||||
MU_WRITE_LOG("serialized contacts cache %s",
|
MU_WRITE_LOG("serialized contacts cache %s",
|
||||||
self->_path);
|
self->_path);
|
||||||
}
|
|
||||||
|
|
||||||
if (self->_ccache)
|
if (self->_ccache)
|
||||||
g_key_file_free (self->_ccache);
|
g_key_file_free (self->_ccache);
|
||||||
@ -471,9 +470,8 @@ mu_contacts_destroy (MuContacts *self)
|
|||||||
g_free (self);
|
g_free (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* note, we will *own* the name, email we get, and we'll free them in the
|
||||||
/* note, we will *own* the name, email we get, and we'll free them in
|
* end... */
|
||||||
* the end... */
|
|
||||||
static ContactInfo *
|
static ContactInfo *
|
||||||
contact_info_new (char *email, char *name, gboolean personal, time_t tstamp,
|
contact_info_new (char *email, char *name, gboolean personal, time_t tstamp,
|
||||||
unsigned freq)
|
unsigned freq)
|
||||||
|
|||||||
@ -111,7 +111,7 @@ typedef void (*MuContactsForeachFunc) (const char *email, const char *name,
|
|||||||
* call a function for either each contact, or each contact satisfying
|
* call a function for either each contact, or each contact satisfying
|
||||||
* a regular expression,
|
* a regular expression,
|
||||||
*
|
*
|
||||||
* @param contacts contacts object
|
* @param self contacts object
|
||||||
* @param func callback function to be called for each
|
* @param func callback function to be called for each
|
||||||
* @param user_data user data to pass to the callback
|
* @param user_data user data to pass to the callback
|
||||||
* @param pattern a regular expression which matches either the e-mail
|
* @param pattern a regular expression which matches either the e-mail
|
||||||
@ -124,6 +124,15 @@ typedef void (*MuContactsForeachFunc) (const char *email, const char *name,
|
|||||||
gboolean mu_contacts_foreach (MuContacts *self, MuContactsForeachFunc func,
|
gboolean mu_contacts_foreach (MuContacts *self, MuContactsForeachFunc func,
|
||||||
gpointer user_data, const char* pattern, size_t *num);
|
gpointer user_data, const char* pattern, size_t *num);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* serialize the contacts to the contacts cache file
|
||||||
|
*
|
||||||
|
* @param self contacts object
|
||||||
|
*
|
||||||
|
* @return TRUE if the function succeeded, FALSE otherwise
|
||||||
|
* */
|
||||||
|
gboolean mu_contacts_serialize (MuContacts *self);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /*__MU_CONTACTS_H__*/
|
#endif /*__MU_CONTACTS_H__*/
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* -*-mode: c++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8-*- */
|
/* -*-mode: c++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8-*- */
|
||||||
/*
|
/*
|
||||||
** Copyright (C) 2011-2012 <djcb@djcbsoftware.nl>
|
** Copyright (C) 2011-2016 <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify it
|
** This program is free software; you can redistribute it and/or modify it
|
||||||
** under the terms of the GNU General Public License as published by the
|
** under the terms of the GNU General Public License as published by the
|
||||||
@ -148,6 +148,8 @@ public:
|
|||||||
g_warning ("ref count != 0");
|
g_warning ("ref count != 0");
|
||||||
|
|
||||||
mu_contacts_destroy (_contacts);
|
mu_contacts_destroy (_contacts);
|
||||||
|
_contacts = NULL;
|
||||||
|
|
||||||
if (!_read_only)
|
if (!_read_only)
|
||||||
mu_store_flush (this);
|
mu_store_flush (this);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* -*-mode: c++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8-*- */
|
/* -*-mode: c++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8-*- */
|
||||||
/*
|
/*
|
||||||
** Copyright (C) 2008-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2008-2016 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify it
|
** This program is free software; you can redistribute it and/or modify it
|
||||||
** under the terms of the GNU General Public License as published by the
|
** under the terms of the GNU General Public License as published by the
|
||||||
@ -197,6 +197,9 @@ mu_store_flush (MuStore *store)
|
|||||||
store->db_writable()->commit ();
|
store->db_writable()->commit ();
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK;
|
} MU_XAPIAN_CATCH_BLOCK;
|
||||||
|
|
||||||
|
if (store->contacts())
|
||||||
|
mu_contacts_serialize (store->contacts());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -669,9 +672,11 @@ each_contact_check_if_personal (MuMsgContact *contact, MsgDoc *msgdoc)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
for (cur = msgdoc->_my_addresses; cur; cur = g_slist_next (cur)) {
|
for (cur = msgdoc->_my_addresses; cur; cur = g_slist_next (cur)) {
|
||||||
if (g_ascii_strcasecmp (contact->address,
|
if (g_ascii_strcasecmp (
|
||||||
(const char*)cur->data) == 0)
|
contact->address, (const char*)cur->data) == 0) {
|
||||||
msgdoc->_personal = TRUE;
|
msgdoc->_personal = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -168,7 +168,8 @@ const char* mu_store_version (const MuStore *store);
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* try to flush/commit all outstanding work
|
* try to flush/commit all outstanding work to the database and the contacts
|
||||||
|
* cache.
|
||||||
*
|
*
|
||||||
* @param store a valid xapian store
|
* @param store a valid xapian store
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user