lib: cache user prefixes in database object
authorDavid Bremner <david@tethera.net>
Sat, 17 Nov 2018 14:09:00 +0000 (10:09 -0400)
committerDavid Bremner <david@tethera.net>
Sat, 25 May 2019 10:08:20 +0000 (07:08 -0300)
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 separate 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
lib/database.cc
lib/notmuch-private.h
lib/thread.cc

index 293f2db42a31ff2cd0dbc73ff9775c53d8de85d5..9d1dabf109625896363b21e9c417dafd7d5d95e6 100644 (file)
@@ -221,6 +221,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
index dd1c1c7d8f7848edd0a675234561fc2f3ec95e4b..4f02815ffa6e45593a6a89fec7e3c98d3efeb84c 100644 (file)
@@ -334,6 +334,14 @@ _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;
@@ -345,6 +353,14 @@ _setup_user_query_fields (notmuch_database_t *notmuch)
        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));
+
+       _notmuch_string_map_append (notmuch->user_header,
+                                   key,
+                                   notmuch_config_list_value (list));
+
        query_field.name = talloc_strdup (notmuch, key);
        query_field.prefix = _user_prefix (notmuch, key);
        query_field.flags = NOTMUCH_FIELD_PROBABILISTIC
index 39d11a917b20a7f256f707829438b88ea0cfe379..09f828abfffbaec47aa57611728191ef9975cba4 100644 (file)
@@ -678,6 +678,8 @@ struct _notmuch_indexopts {
 
 #define CONFIG_HEADER_PREFIX "index.header."
 
+#define EMPTY_STRING(s) ((s)[0] == '\0')
+
 NOTMUCH_END_DECLS
 
 #ifdef __cplusplus
index c9c9398fd9d0788e2cebe86d43848ebc82a5a412..fd0e1393be51f17011ca3b96b190f8a8159ce606 100644 (file)
@@ -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;