unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 4/7] lib: cache user prefixes in database object
Date: Sat,  2 Mar 2019 11:41:30 -0400	[thread overview]
Message-ID: <20190302154133.25642-5-david@tethera.net> (raw)
In-Reply-To: <20190302154133.25642-1-david@tethera.net>

This will be used to avoid needing a database access to resolve a db
prefix from the corresponding UI prefix (e.g. when indexing). Arguably
the setup of the seperate header map does not belong here, since it is
about indexing rather than querying, but we currently don't have any
other indexing setup to do.
---
 lib/database-private.h |  5 +++++
 lib/database.cc        | 39 ++++++++++++++++++++++++++++-----------
 lib/notmuch-private.h  |  9 +++++++++
 lib/thread.cc          |  2 --
 4 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/lib/database-private.h b/lib/database-private.h
index a499b259..57fddada 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -215,6 +215,11 @@ struct _notmuch_database {
     Xapian::ValueRangeProcessor *value_range_processor;
     Xapian::ValueRangeProcessor *date_range_processor;
     Xapian::ValueRangeProcessor *last_mod_range_processor;
+
+    /* XXX it's slightly gross to use two parallel string->string maps
+     * here, but at least they are small */
+    notmuch_string_map_t *user_prefix;
+    notmuch_string_map_t *user_header;
 };
 
 /* Prior to database version 3, features were implied by the database
diff --git a/lib/database.cc b/lib/database.cc
index 4de79f79..6caa1311 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -299,8 +299,6 @@ prefix_t prefix_table[] = {
 						NOTMUCH_FIELD_PROCESSOR},
 };
 
-#define CONFIG_HEADER_PREFIX "index.header."
-
 static void
 _setup_query_field_default (const prefix_t *prefix, notmuch_database_t *notmuch)
 {
@@ -310,29 +308,48 @@ _setup_query_field_default (const prefix_t *prefix, notmuch_database_t *notmuch)
 	notmuch->query_parser->add_boolean_prefix (prefix->name, prefix->prefix);
 }
 
+const char *
+_user_prefix (void *ctx, const char* name)
+{
+    return talloc_asprintf(ctx, "XU%s:", name);
+}
+
 static notmuch_status_t
 _setup_user_query_fields (notmuch_database_t *notmuch)
 {
     notmuch_config_list_t *list;
     notmuch_status_t status;
 
+    notmuch->user_prefix = _notmuch_string_map_create (notmuch);
+    if (notmuch->user_prefix == NULL)
+	return NOTMUCH_STATUS_OUT_OF_MEMORY;
+
+    notmuch->user_header = _notmuch_string_map_create (notmuch);
+    if (notmuch->user_header == NULL)
+	return NOTMUCH_STATUS_OUT_OF_MEMORY;
+
     status = notmuch_database_get_config_list (notmuch, CONFIG_HEADER_PREFIX, &list);
     if (status)
 	return status;
+
     for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
 
-	prefix_t query_field { .name = NULL, .prefix = NULL,
-		.flags = NOTMUCH_FIELD_PROBABILISTIC |
-			 NOTMUCH_FIELD_EXTERNAL
-		};
+	prefix_t query_field;
+
+	const char *key = notmuch_config_list_key (list) +
+	    	    + sizeof (CONFIG_HEADER_PREFIX) - 1;
 
-	const char *key = notmuch_config_list_key (list)
-	    + sizeof (CONFIG_HEADER_PREFIX) - 1;
+	_notmuch_string_map_append (notmuch->user_prefix,
+				    key,
+				    _user_prefix (notmuch, key));
 
-	char *prefix = talloc_asprintf(notmuch, "XU%s:", key);
+	_notmuch_string_map_append (notmuch->user_header,
+				    key,
+				    notmuch_config_list_value (list));
 
-	query_field.name = key;
-	query_field.prefix = prefix;
+	query_field.name = talloc_strdup(notmuch, key);
+	query_field.prefix = _user_prefix(notmuch, key);
+	query_field.flags = NOTMUCH_FIELD_PROBABILISTIC | NOTMUCH_FIELD_EXTERNAL;
 
 	_setup_query_field_default (&query_field, notmuch);
     }
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index df32d39c..1ef26e37 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -181,6 +181,11 @@ typedef struct _notmuch_doc_id_set notmuch_doc_id_set_t;
 const char *
 _find_prefix (const char *name);
 
+/* Lookup a prefix value by name, including possibly user defined prefixes
+ */
+const char *
+_notmuch_database_prefix (notmuch_database_t  *notmuch, const char *name);
+
 char *
 _notmuch_message_id_compressed (void *ctx, const char *message_id);
 
@@ -676,6 +681,10 @@ struct _notmuch_indexopts {
     _notmuch_crypto_t crypto;
 };
 
+#define CONFIG_HEADER_PREFIX "index.header."
+
+#define EMPTY_STRING(s) ((s)[0] == '\0')
+
 NOTMUCH_END_DECLS
 
 #ifdef __cplusplus
diff --git a/lib/thread.cc b/lib/thread.cc
index 47c90664..ae830064 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -30,8 +30,6 @@
 #define THREAD_DEBUG(format, ...) do {} while (0) /* ignored */
 #endif
 
-#define EMPTY_STRING(s) ((s)[0] == '\0')
-
 struct _notmuch_thread {
     notmuch_database_t *notmuch;
     char *thread_id;
-- 
2.20.1

  parent reply	other threads:[~2019-03-02 15:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-02 15:41 WIP2: index user headers David Bremner
2019-03-02 15:41 ` [PATCH 1/7] cli/config: refactor _stored_in_db David Bremner
2019-03-02 15:41 ` [PATCH 2/7] cli/config: support user header index config David Bremner
2019-03-02 15:41 ` [PATCH 3/7] lib: setup user headers in query parser David Bremner
2019-03-02 15:41 ` David Bremner [this message]
2019-03-02 15:41 ` [PATCH 5/7] lib: support user prefix names in term generation David Bremner
2019-03-02 15:41 ` [PATCH 6/7] lib/database: index user headers David Bremner
2019-03-02 15:41 ` [PATCH 7/7] doc: document user header indexing David Bremner
2019-03-02 15:43 ` WIP2: index user headers David Bremner
2019-03-03 14:56 ` David Bremner
2019-03-04  1:54   ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190302154133.25642-5-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).