]> git.notmuchmail.org Git - notmuch/blobdiff - lib/database.cc
lib: add versions of n_q_count_{message,threads} with status return
[notmuch] / lib / database.cc
index fc78769318cce7d15f0e950a3b638d2f68a6a920..f39d4485076cf9e855f6d7fe2401d4b1cf1894b4 100644 (file)
@@ -1000,6 +1000,7 @@ notmuch_database_open_verbose (const char *path,
        notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));
        notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);
        notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);
+       notmuch->last_mod_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:");
 
        notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);
        notmuch->query_parser->set_database (*notmuch->xapian_db);
@@ -1007,6 +1008,7 @@ notmuch_database_open_verbose (const char *path,
        notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);
        notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);
        notmuch->query_parser->add_valuerangeprocessor (notmuch->date_range_processor);
+       notmuch->query_parser->add_valuerangeprocessor (notmuch->last_mod_range_processor);
 
        for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {
            prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];
@@ -1085,6 +1087,8 @@ notmuch_database_close (notmuch_database_t *notmuch)
     notmuch->value_range_processor = NULL;
     delete notmuch->date_range_processor;
     notmuch->date_range_processor = NULL;
+    delete notmuch->last_mod_range_processor;
+    notmuch->last_mod_range_processor = NULL;
 
     return status;
 }
@@ -1368,6 +1372,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
     enum _notmuch_features target_features, new_features;
     notmuch_status_t status;
     notmuch_private_status_t private_status;
+    notmuch_query_t *query = NULL;
     unsigned int count = 0, total = 0;
 
     status = _notmuch_database_ensure_writable (notmuch);
@@ -1404,9 +1409,16 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
     if (new_features &
        (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |
         NOTMUCH_FEATURE_LAST_MOD)) {
-       notmuch_query_t *query = notmuch_query_create (notmuch, "");
-       total += notmuch_query_count_messages (query);
+       query = notmuch_query_create (notmuch, "");
+       unsigned msg_count;
+
+       status = notmuch_query_count_messages_st (query, &msg_count);
+       if (status)
+           goto DONE;
+
+       total += msg_count;
        notmuch_query_destroy (query);
+       query = NULL;
     }
     if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {
        t_end = db->allterms_end ("XTIMESTAMP");
@@ -1432,11 +1444,14 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
     if (new_features &
        (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |
         NOTMUCH_FEATURE_LAST_MOD)) {
-       notmuch_query_t *query = notmuch_query_create (notmuch, "");
        notmuch_messages_t *messages;
        notmuch_message_t *message;
        char *filename;
 
+       query = notmuch_query_create (notmuch, "");
+
+       /* XXX: this should use the _st version, but needs an error
+          path */
        for (messages = notmuch_query_search_messages (query);
             notmuch_messages_valid (messages);
             notmuch_messages_move_to_next (messages))
@@ -1484,6 +1499,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
        }
 
        notmuch_query_destroy (query);
+       query = NULL;
     }
 
     /* Perform per-directory upgrades. */
@@ -1604,6 +1620,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
        sigaction (SIGALRM, &action, NULL);
     }
 
+    if (query)
+       notmuch_query_destroy (query);
+
     talloc_free (local);
     return status;
 }
@@ -2647,7 +2666,7 @@ notmuch_database_get_all_tags (notmuch_database_t *db)
 }
 
 const char *
-notmuch_database_status_string (notmuch_database_t *notmuch)
+notmuch_database_status_string (const notmuch_database_t *notmuch)
 {
     return notmuch->status_string;
 }