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 -*-*/
|
||||
/*
|
||||
** 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
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
@ -280,8 +280,6 @@ clear_str (char* str)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
gboolean
|
||||
mu_contacts_add (MuContacts *self, const char *addr, const char *name,
|
||||
gboolean personal, time_t tstamp)
|
||||
@ -304,7 +302,7 @@ mu_contacts_add (MuContacts *self, const char *addr, const char *name,
|
||||
tstamp, 1);
|
||||
g_hash_table_insert (self->_hash, g_strdup(group), cinfo);
|
||||
} 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 */
|
||||
if (personal)
|
||||
cinfo->_personal = TRUE;
|
||||
@ -421,21 +419,23 @@ each_keyval (const char *group, ContactInfo *cinfo, MuContacts *self)
|
||||
(int)cinfo->_freq);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
serialize_cache (MuContacts *self)
|
||||
gboolean
|
||||
mu_contacts_serialize (MuContacts *self)
|
||||
{
|
||||
gchar *data;
|
||||
gsize len;
|
||||
gboolean rv;
|
||||
gchar *data;
|
||||
gsize len;
|
||||
gboolean rv;
|
||||
|
||||
g_return_val_if_fail (self, FALSE);
|
||||
|
||||
g_hash_table_foreach (self->_hash, (GHFunc)each_keyval, self);
|
||||
|
||||
/* Note: err arg is unused */
|
||||
data = g_key_file_to_data (self->_ccache, &len, NULL);
|
||||
data = g_key_file_to_data (self->_ccache, &len, NULL);
|
||||
if (len) {
|
||||
GError *err;
|
||||
GError *err;
|
||||
err = NULL;
|
||||
rv = g_file_set_contents (self->_path, data, len, &err);
|
||||
rv = g_file_set_contents (self->_path, data, len, &err);
|
||||
if (!rv) {
|
||||
g_warning ("failed to serialize cache to %s: %s",
|
||||
self->_path, err->message);
|
||||
@ -454,12 +454,11 @@ mu_contacts_destroy (MuContacts *self)
|
||||
if (!self)
|
||||
return;
|
||||
|
||||
if (self->_ccache && self->_dirty) {
|
||||
serialize_cache (self);
|
||||
if (self->_ccache && self->_dirty &&
|
||||
mu_contacts_serialize (self))
|
||||
MU_WRITE_LOG("serialized contacts cache %s",
|
||||
self->_path);
|
||||
}
|
||||
|
||||
|
||||
if (self->_ccache)
|
||||
g_key_file_free (self->_ccache);
|
||||
|
||||
@ -471,9 +470,8 @@ mu_contacts_destroy (MuContacts *self)
|
||||
g_free (self);
|
||||
}
|
||||
|
||||
|
||||
/* note, we will *own* the name, email we get, and we'll free them in
|
||||
* the end... */
|
||||
/* note, we will *own* the name, email we get, and we'll free them in the
|
||||
* end... */
|
||||
static ContactInfo *
|
||||
contact_info_new (char *email, char *name, gboolean personal, time_t tstamp,
|
||||
unsigned freq)
|
||||
|
||||
Reference in New Issue
Block a user