mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-12-22 17:34:54 +01:00
database: Add private find_unique_doc_id and find_unique_document functions
These are a generalization of the unique-ness testing of notmuch_database_find_message. More preparation for firectory timestamps.
This commit is contained in:
parent
edbf7f645c
commit
668f20bdfb
2 changed files with 45 additions and 4 deletions
48
database.cc
48
database.cc
|
@ -92,12 +92,51 @@ find_doc_ids (notmuch_database_t *notmuch,
|
||||||
free (term);
|
free (term);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static notmuch_private_status_t
|
||||||
|
find_unique_doc_id (notmuch_database_t *notmuch,
|
||||||
|
const char *prefix_name,
|
||||||
|
const char *value,
|
||||||
|
unsigned int *doc_id)
|
||||||
|
{
|
||||||
|
Xapian::PostingIterator i, end;
|
||||||
|
|
||||||
|
find_doc_ids (notmuch, prefix_name, value, &i, &end);
|
||||||
|
|
||||||
|
if (i == end) {
|
||||||
|
*doc_id = 0;
|
||||||
|
return NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND;
|
||||||
|
} else {
|
||||||
|
*doc_id = *i;
|
||||||
|
return NOTMUCH_PRIVATE_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static Xapian::Document
|
static Xapian::Document
|
||||||
find_document_for_doc_id (notmuch_database_t *notmuch, unsigned doc_id)
|
find_document_for_doc_id (notmuch_database_t *notmuch, unsigned doc_id)
|
||||||
{
|
{
|
||||||
return notmuch->xapian_db->get_document (doc_id);
|
return notmuch->xapian_db->get_document (doc_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static notmuch_private_status_t
|
||||||
|
find_unique_document (notmuch_database_t *notmuch,
|
||||||
|
const char *prefix_name,
|
||||||
|
const char *value,
|
||||||
|
Xapian::Document *document,
|
||||||
|
unsigned int *doc_id)
|
||||||
|
{
|
||||||
|
notmuch_private_status_t status;
|
||||||
|
|
||||||
|
status = find_unique_doc_id (notmuch, prefix_name, value, doc_id);
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
*document = Xapian::Document ();
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
*document = find_document_for_doc_id (notmuch, *doc_id);
|
||||||
|
return NOTMUCH_PRIVATE_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
insert_thread_id (GHashTable *thread_ids, Xapian::Document doc)
|
insert_thread_id (GHashTable *thread_ids, Xapian::Document doc)
|
||||||
{
|
{
|
||||||
|
@ -125,14 +164,15 @@ notmuch_message_t *
|
||||||
notmuch_database_find_message (notmuch_database_t *notmuch,
|
notmuch_database_find_message (notmuch_database_t *notmuch,
|
||||||
const char *message_id)
|
const char *message_id)
|
||||||
{
|
{
|
||||||
Xapian::PostingIterator i, end;
|
notmuch_private_status_t status;
|
||||||
|
unsigned int doc_id;
|
||||||
|
|
||||||
find_doc_ids (notmuch, "msgid", message_id, &i, &end);
|
status = find_unique_doc_id (notmuch, "msgid", message_id, &doc_id);
|
||||||
|
|
||||||
if (i == end)
|
if (status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return _notmuch_message_create (notmuch, notmuch, *i);
|
return _notmuch_message_create (notmuch, notmuch, doc_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return one or more thread_ids, (as a GPtrArray of strings), for the
|
/* Return one or more thread_ids, (as a GPtrArray of strings), for the
|
||||||
|
|
|
@ -91,6 +91,7 @@ typedef enum _notmuch_private_status {
|
||||||
|
|
||||||
/* Then add our own private values. */
|
/* Then add our own private values. */
|
||||||
NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG,
|
NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG,
|
||||||
|
NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND,
|
||||||
|
|
||||||
NOTMUCH_PRIVATE_STATUS_LAST_STATUS
|
NOTMUCH_PRIVATE_STATUS_LAST_STATUS
|
||||||
} notmuch_private_status_t;
|
} notmuch_private_status_t;
|
||||||
|
|
Loading…
Reference in a new issue