* lib: cleanups: remove mu-msg-cache (WIP)
This commit is contained in:
145
lib/mu-msg.c
145
lib/mu-msg.c
@ -73,12 +73,7 @@ msg_new (void)
|
||||
MuMsg *self;
|
||||
|
||||
self = g_slice_new0 (MuMsg);
|
||||
|
||||
self->_refcount = 1;
|
||||
self->_cache = mu_msg_cache_new ();
|
||||
|
||||
self->_file = NULL;
|
||||
self->_doc = NULL;
|
||||
|
||||
return self;
|
||||
}
|
||||
@ -108,8 +103,6 @@ mu_msg_new_from_file (const char *path, const char *mdir,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
MuMsg*
|
||||
mu_msg_new_from_doc (XapianDocument *doc, GError **err)
|
||||
{
|
||||
@ -143,7 +136,13 @@ mu_msg_destroy (MuMsg *self)
|
||||
mu_msg_file_destroy (self->_file);
|
||||
mu_msg_doc_destroy (self->_doc);
|
||||
|
||||
mu_msg_cache_destroy (self->_cache);
|
||||
|
||||
{ /* cleanup the strings / lists we stored */
|
||||
mu_str_free_list (self->_free_later_str);
|
||||
g_slist_foreach (self->_free_later_lst,
|
||||
(GFunc)mu_str_free_list, NULL);
|
||||
g_slist_free (self->_free_later_lst);
|
||||
}
|
||||
|
||||
g_slice_free (MuMsg, self);
|
||||
}
|
||||
@ -169,46 +168,51 @@ mu_msg_unref (MuMsg *self)
|
||||
mu_msg_destroy (self);
|
||||
}
|
||||
|
||||
static const gchar*
|
||||
free_later_str (MuMsg *self, gchar *str)
|
||||
{
|
||||
if (str)
|
||||
self->_free_later_str =
|
||||
g_slist_prepend (self->_free_later_str, str);
|
||||
return str;
|
||||
}
|
||||
|
||||
static const GSList*
|
||||
free_later_lst (MuMsg *self, GSList *lst)
|
||||
{
|
||||
if (lst)
|
||||
self->_free_later_lst =
|
||||
g_slist_prepend (self->_free_later_lst, lst);
|
||||
return lst;
|
||||
}
|
||||
|
||||
|
||||
/* use this instead of mu_msg_get_path so we don't get into infinite
|
||||
* regress...*/
|
||||
static const char*
|
||||
get_path (MuMsg *self)
|
||||
{
|
||||
const char *path;
|
||||
char *val;
|
||||
gboolean do_free;
|
||||
|
||||
/* try to get the path from the cache */
|
||||
path = mu_msg_cache_str (self->_cache, MU_MSG_FIELD_ID_PATH);
|
||||
if (path)
|
||||
return path;
|
||||
do_free = TRUE;
|
||||
val = NULL;
|
||||
|
||||
/* nothing found yet? try the doc in case we are using that
|
||||
* backend */
|
||||
val = NULL;
|
||||
if (self->_doc)
|
||||
val = mu_msg_doc_get_str_field (self->_doc,
|
||||
MU_MSG_FIELD_ID_PATH,
|
||||
&do_free);
|
||||
val = mu_msg_doc_get_str_field
|
||||
(self->_doc, MU_MSG_FIELD_ID_PATH);
|
||||
|
||||
/* not in the cache yet? try to get it from the file backend,
|
||||
* in case we are using that */
|
||||
if (!val && self->_file)
|
||||
val = mu_msg_file_get_str_field (self->_file,
|
||||
MU_MSG_FIELD_ID_PATH,
|
||||
&do_free);
|
||||
val = mu_msg_file_get_str_field
|
||||
(self->_file, MU_MSG_FIELD_ID_PATH, &do_free);
|
||||
|
||||
/* this cannot happen unless there are bugs in mu */
|
||||
if (!val) {
|
||||
/* shouldn't happen */
|
||||
if (!val)
|
||||
g_warning ("%s: cannot find path", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* we found something */
|
||||
return mu_msg_cache_set_str (self->_cache,
|
||||
MU_MSG_FIELD_ID_PATH, val,
|
||||
do_free);
|
||||
return free_later_str (self, val);
|
||||
}
|
||||
|
||||
|
||||
@ -245,57 +249,39 @@ mu_msg_unload_msg_file (MuMsg *msg)
|
||||
}
|
||||
|
||||
|
||||
|
||||
static const GSList*
|
||||
get_str_list_field (MuMsg *self, MuMsgFieldId mfid)
|
||||
{
|
||||
gboolean do_free;
|
||||
GSList *val;
|
||||
|
||||
/* first we try the cache */
|
||||
if (mu_msg_cache_cached (self->_cache, mfid))
|
||||
return mu_msg_cache_str_list (self->_cache, mfid);
|
||||
|
||||
/* if it's not in the cache but it is a value retrievable from
|
||||
* the doc backend, use that */
|
||||
val = NULL;
|
||||
|
||||
if (self->_doc && mu_msg_field_xapian_value (mfid))
|
||||
val = mu_msg_doc_get_str_list_field (self->_doc,
|
||||
mfid, &do_free);
|
||||
else {
|
||||
val = mu_msg_doc_get_str_list_field (self->_doc, mfid);
|
||||
if (!val) {
|
||||
/* if we don't have a file object yet, we need to
|
||||
* create it from the file on disk */
|
||||
if (!mu_msg_load_msg_file (self, NULL))
|
||||
return NULL;
|
||||
val = mu_msg_file_get_str_list_field (self->_file, mfid,
|
||||
&do_free);
|
||||
val = mu_msg_file_get_str_list_field (self->_file, mfid);
|
||||
}
|
||||
|
||||
/* if we get a string that needs freeing, we tell the cache to
|
||||
* mark the string as such, so it will be freed when the cache
|
||||
* is freed (or when the value is overwritten) */
|
||||
return mu_msg_cache_set_str_list (self->_cache, mfid, val,
|
||||
do_free);
|
||||
return free_later_lst (self, val);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static const char*
|
||||
get_str_field (MuMsg *self, MuMsgFieldId mfid)
|
||||
{
|
||||
gboolean do_free;
|
||||
char *val;
|
||||
gboolean do_free;
|
||||
|
||||
/* first we try the cache */
|
||||
if (mu_msg_cache_cached (self->_cache, mfid))
|
||||
return mu_msg_cache_str (self->_cache, mfid);
|
||||
|
||||
/* if it's not in the cache but it is a value retrievable from
|
||||
* the doc backend, use that */
|
||||
do_free = FALSE;
|
||||
val = NULL;
|
||||
|
||||
if (self->_doc && mu_msg_field_xapian_value (mfid))
|
||||
val = mu_msg_doc_get_str_field (self->_doc, mfid, &do_free);
|
||||
val = mu_msg_doc_get_str_field (self->_doc, mfid);
|
||||
|
||||
else if (mu_msg_field_gmime (mfid)) {
|
||||
/* if we don't have a file object yet, we need to
|
||||
* create it from the file on disk */
|
||||
@ -304,13 +290,10 @@ get_str_field (MuMsg *self, MuMsgFieldId mfid)
|
||||
val = mu_msg_file_get_str_field (self->_file, mfid, &do_free);
|
||||
} else {
|
||||
g_warning ("%s: cannot retrieve field", __FUNCTION__);
|
||||
return NULL;
|
||||
val = NULL;
|
||||
}
|
||||
|
||||
/* if we get a string that needs freeing, we tell the cache to
|
||||
* mark the string as such, so it will be freed when the cache
|
||||
* is freed (or when the value is overwritten) */
|
||||
return mu_msg_cache_set_str (self->_cache, mfid, val, do_free);
|
||||
return do_free ? free_later_str (self, val) : val;
|
||||
}
|
||||
|
||||
|
||||
@ -319,12 +302,6 @@ get_num_field (MuMsg *self, MuMsgFieldId mfid)
|
||||
{
|
||||
guint64 val;
|
||||
|
||||
/* first try the cache */
|
||||
if (mu_msg_cache_cached (self->_cache, mfid))
|
||||
return mu_msg_cache_num (self->_cache, mfid);
|
||||
|
||||
/* if it's not in the cache but it is a value retrievable from
|
||||
* the doc backend, use that */
|
||||
val = -1;
|
||||
if (self->_doc && mu_msg_field_xapian_value (mfid))
|
||||
val = mu_msg_doc_get_num_field (self->_doc, mfid);
|
||||
@ -336,7 +313,7 @@ get_num_field (MuMsg *self, MuMsgFieldId mfid)
|
||||
val = mu_msg_file_get_num_field (self->_file, mfid);
|
||||
}
|
||||
|
||||
return mu_msg_cache_set_num (self->_cache, mfid, val);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
@ -833,8 +810,6 @@ get_target_mdir (MuMsg *msg, const char *target_maildir, GError **err)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* move a msg to another maildir, trying to maintain 'integrity',
|
||||
* ie. msg in 'new/' will go to new/, one in cur/ goes to cur/. be
|
||||
@ -861,24 +836,14 @@ mu_msg_move_to_maildir (MuMsg *self, const char *maildir,
|
||||
|
||||
/* update the message path and the flags; they may have
|
||||
* changed */
|
||||
if (newfullpath) {
|
||||
mu_msg_cache_set_str (self->_cache, MU_MSG_FIELD_ID_PATH, newfullpath,
|
||||
TRUE); /* the cache will free the string */
|
||||
mu_msg_cache_set_str (self->_cache, MU_MSG_FIELD_ID_MAILDIR,
|
||||
g_strdup(maildir), TRUE);
|
||||
/* the cache will free the string */
|
||||
if (!newfullpath)
|
||||
return FALSE;
|
||||
|
||||
/* the contentflags haven't changed, so make sure they persist */
|
||||
flags |= mu_msg_get_flags (self) &
|
||||
(MU_FLAG_HAS_ATTACH|MU_FLAG_ENCRYPTED|MU_FLAG_SIGNED);
|
||||
/* update the pseudo-flag as well */
|
||||
if (!(flags & MU_FLAG_NEW) && (flags & MU_FLAG_SEEN))
|
||||
flags &= ~MU_FLAG_UNREAD;
|
||||
else
|
||||
flags |= MU_FLAG_UNREAD;
|
||||
/* clear the old backends */
|
||||
mu_msg_doc_destroy (self->_doc);
|
||||
mu_msg_file_destroy (self->_file);
|
||||
|
||||
mu_msg_cache_set_num (self->_cache, MU_MSG_FIELD_ID_FLAGS, flags);
|
||||
}
|
||||
|
||||
return newfullpath ? TRUE : FALSE;
|
||||
/* and create a new one */
|
||||
self->_file = mu_msg_file_new (newfullpath, targetmdir, err);
|
||||
return self->_file ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user