mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-12-22 17:34:54 +01:00
Drop the storage of thread ID(s) in a value.
Now that we are iterating over the thread terms instead, we can drop this redundant storage (which should shrink our database a tiny bit).
This commit is contained in:
parent
5941b91a5e
commit
1c2bac747e
3 changed files with 25 additions and 37 deletions
38
database.cc
38
database.cc
|
@ -192,26 +192,34 @@ find_unique_document (notmuch_database_t *notmuch,
|
|||
return NOTMUCH_PRIVATE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* XXX: Should rewrite this to accept a notmuch_message_t* instead of
|
||||
* a Xapian:Document and then we could just use
|
||||
* notmuch_message_get_thread_ids instead of duplicating its logic
|
||||
* here. */
|
||||
static void
|
||||
insert_thread_id (GHashTable *thread_ids, Xapian::Document doc)
|
||||
{
|
||||
string value_string;
|
||||
const char *value, *id, *comma;
|
||||
Xapian::TermIterator i;
|
||||
const char *prefix_str = _find_prefix ("thread");
|
||||
char prefix;
|
||||
|
||||
value_string = doc.get_value (NOTMUCH_VALUE_THREAD);
|
||||
value = value_string.c_str();
|
||||
if (strlen (value)) {
|
||||
id = value;
|
||||
while (*id) {
|
||||
comma = strchr (id, ',');
|
||||
if (comma == NULL)
|
||||
comma = id + strlen (id);
|
||||
g_hash_table_insert (thread_ids,
|
||||
strndup (id, comma - id), NULL);
|
||||
id = comma;
|
||||
if (*id)
|
||||
id++;
|
||||
}
|
||||
assert (strlen (prefix_str) == 1);
|
||||
|
||||
prefix = *prefix_str;
|
||||
|
||||
i = doc.termlist_begin ();
|
||||
i.skip_to (prefix_str);
|
||||
|
||||
while (1) {
|
||||
if (i == doc.termlist_end ())
|
||||
break;
|
||||
value_string = *i;
|
||||
if (value_string.empty () || value_string[0] != prefix)
|
||||
break;
|
||||
g_hash_table_insert (thread_ids,
|
||||
strdup (value_string.c_str () + 1), NULL);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
20
message.cc
20
message.cc
|
@ -292,26 +292,7 @@ void
|
|||
_notmuch_message_add_thread_id (notmuch_message_t *message,
|
||||
const char *thread_id)
|
||||
{
|
||||
std::string id_str;
|
||||
|
||||
_notmuch_message_add_term (message, "thread", thread_id);
|
||||
|
||||
id_str = message->doc.get_value (NOTMUCH_VALUE_THREAD);
|
||||
|
||||
if (id_str.empty ()) {
|
||||
message->doc.add_value (NOTMUCH_VALUE_THREAD, thread_id);
|
||||
} else {
|
||||
size_t pos;
|
||||
|
||||
/* Think about using a hash here if there's any performance
|
||||
* problem. */
|
||||
pos = id_str.find (thread_id);
|
||||
if (pos == std::string::npos) {
|
||||
id_str.append (",");
|
||||
id_str.append (thread_id);
|
||||
message->doc.add_value (NOTMUCH_VALUE_THREAD, id_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -351,7 +332,6 @@ _notmuch_message_ensure_thread_id (notmuch_message_t *message)
|
|||
|
||||
thread_id_generate (&thread_id);
|
||||
_notmuch_message_add_term (message, "thread", thread_id.str);
|
||||
message->doc.add_value (NOTMUCH_VALUE_THREAD, thread_id.str);
|
||||
}
|
||||
|
||||
/* Synchronize changes made to message->doc out into the database. */
|
||||
|
|
|
@ -40,6 +40,7 @@ NOTMUCH_BEGIN_DECLS
|
|||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <talloc.h>
|
||||
|
||||
|
@ -71,8 +72,7 @@ NOTMUCH_BEGIN_DECLS
|
|||
|
||||
typedef enum {
|
||||
NOTMUCH_VALUE_TIMESTAMP = 0,
|
||||
NOTMUCH_VALUE_MESSAGE_ID,
|
||||
NOTMUCH_VALUE_THREAD
|
||||
NOTMUCH_VALUE_MESSAGE_ID
|
||||
} notmuch_value_t;
|
||||
|
||||
/* Xapian (with flint backend) complains if we provide a term longer
|
||||
|
|
Loading…
Reference in a new issue