[RFC patch 4/5] WIP: store user prefixes

Subject: [RFC patch 4/5] WIP: store user prefixes

Date: Sat, 17 Nov 2018 10:09:00 -0400

To: notmuch@notmuchmail.org

Cc:

From: David Bremner


Maybe this should be unified into one prefix table?
---
 lib/database-private.h |  8 ++++++++
 lib/database.cc        | 32 +++++++++++++++++++-------------
 lib/notmuch-private.h  |  4 ++++
 lib/thread.cc          |  2 --
 4 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/lib/database-private.h b/lib/database-private.h
index a499b259..f5e90099 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -178,6 +178,12 @@ operator&(notmuch_field_flag_t a, notmuch_field_flag_t b)
 				    Xapian::QueryParser::FLAG_WILDCARD | \
 				    Xapian::QueryParser::FLAG_PURE_NOT)
 
+typedef struct {
+    const char *name;
+    const char *prefix;
+    notmuch_field_flag_t flags;
+} prefix_t;
+
 struct _notmuch_database {
     bool exception_reported;
 
@@ -215,6 +221,8 @@ struct _notmuch_database {
     Xapian::ValueRangeProcessor *value_range_processor;
     Xapian::ValueRangeProcessor *date_range_processor;
     Xapian::ValueRangeProcessor *last_mod_range_processor;
+
+    prefix_t *user_prefix;
 };
 
 /* Prior to database version 3, features were implied by the database
diff --git a/lib/database.cc b/lib/database.cc
index fa77eb91..b2654ab7 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -41,12 +41,6 @@ using namespace std;
 
 #define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
 
-typedef struct {
-    const char *name;
-    const char *prefix;
-    notmuch_field_flag_t flags;
-} prefix_t;
-
 #define NOTMUCH_DATABASE_VERSION 3
 
 #define STRINGIFY(s) _SUB_STRINGIFY(s)
@@ -317,15 +311,24 @@ _setup_user_query_fields (notmuch_database_t *notmuch)
     void *local = talloc_new(notmuch);
     notmuch_status_t status;
 
+    size_t prefix_capacity = 4;
+    size_t prefix_index = 0;
+
+    notmuch->user_prefix = talloc_zero_array (notmuch, prefix_t, prefix_capacity);
+    if (notmuch->user_prefix == NULL)
+	return NOTMUCH_STATUS_OUT_OF_MEMORY;
+    
     status = notmuch_database_get_config_list (notmuch, "index.header.", &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
-		};
+	if (prefix_index >= prefix_capacity-1) {
+	    prefix_capacity *= 2;
+	    notmuch->user_prefix = talloc_realloc (notmuch, notmuch->user_prefix, prefix_t, prefix_capacity);
+	}
+
+	prefix_t *query_field =	&(notmuch->user_prefix[prefix_index]);
 
 	const char *key = notmuch_config_list_key (list)
 	    + sizeof (CONFIG_HEADER_PREFIX) - 1;
@@ -334,10 +337,13 @@ _setup_user_query_fields (notmuch_database_t *notmuch)
 	for (char *p = prefix + 1; *p; p++)
 	    *p = toupper (*p);
 
-	query_field.name = key;
-	query_field.prefix = prefix;
+	query_field->name = key;
+	query_field->prefix = prefix;
+	query_field->flags = NOTMUCH_FIELD_PROBABILISTIC | NOTMUCH_FIELD_EXTERNAL;
+
+	_setup_query_field_default (query_field, notmuch);
 
-	_setup_query_field_default (&query_field, notmuch);
+	prefix_index++;
     }
 
     talloc_free (local);
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index df32d39c..09f828ab 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -676,6 +676,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.19.1

_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Thread: