aboutsummaryrefslogtreecommitdiff
path: root/lib/database.cc
AgeCommit message (Collapse)Author
2023-07-22lib/n_d_remove_message: do not remove unique filenameDavid Bremner
It is wasteful to remove a filename term when the whole message document is about to be removed from the database. Profiling with perf shows this takes a significant portion of the time when cleaning up removed files in the database. The logic of n_d_remove_message becomes a bit more convoluted here in order to make the change minimal. It is possible that this function can be further optimized, since the expansion of filename terms into filenames is probably not needed here.
2023-04-02lib: index attachments with mime types matching index.as_textDavid Bremner
Instead of skipping indexing all attachments, we check of a (user configured) mime type that is indexable as text.
2022-12-27lib/database: propagate status code from _notmuch_message_deleteDavid Bremner
_notmuch_message_delete can return (at least) NOTMUCH_STATUS_XAPIAN_EXCEPTION, which we should not ignore.
2022-06-25lib: add NOTMUCH_STATUS_CLOSED_DATABASE, use in _n_d_ensure_writableDavid Bremner
In order for a database to actually be writeable, it must be the case that it is open, not just the correct type of Xapian object. By explicitely checking, we are able to provide better error reporting, in particular for the previously broken test in T566-lib-message.
2022-01-22lib/database: delete stemmer on destroyDavid Bremner
Commit [0] left the stemmer object accessible, but did not add de-allocation code to notmuch_database_destroy. This commit corrects that oversight. Leak originally reported by Austin Ray [1]. [0]: 3202e0d1feba1ab955ba1c07098c00208f8f0ada [1]: id:20220105224538.m36lnjn7rf3ieonc@athena
2022-01-15lib/open: no default mail root in split configurationsDavid Bremner
If we know the configuration is split, but there is no mail root defined, this indicates a (lack of) configuration error. Currently this can only arise in XDG configurations.
2021-10-30lib/compact: replace deprecated notmuch_database_open_verboseDavid Bremner
It should not be necesary to have any config information here, hence passing "" to n_d_open_with_config.
2021-09-04lib: add new status code for query syntax errors.David Bremner
This will help provide more meaningful error messages without special casing on the client side.
2021-06-27lib: autocommit after some number of completed transactionsDavid Bremner
This change addresses two known issues with large sets of changes to the database. The first is that as reported by Steven Allen [1], notmuch commits are not "flushed" when they complete, which means that if there is an open transaction when the database closes (or e.g. the program crashes) then all changes since the last commit will be discarded (nothing is irrecoverably lost for "notmuch new", as the indexing process just restarts next time it is run). This does not really "fix" the issue reported in [1]; that seems rather difficult given how transactions work in Xapian. On the other hand, with the default settings, this should mean one only loses less than a minutes worth of work. The second issue is the occasionally reported "storm" of disk writes when notmuch finishes. I don't yet have a test for this, but I think committing as we go should reduce the amount of work when finalizing the database. [1]: id:20151025210215.GA3754@stebalien.com
2021-06-27database/close: remove misleading code / commentDavid Bremner
Unfortunately, it doesn't make a difference if we call cancel_transaction or not, all uncommited changes are discarded if there is an open (unflushed) transaction.
2021-06-27lib/database: fix style mistake.David Bremner
The spacing of the declaration was wrong in ea30110.
2021-06-25lib: write talloc report in notmuch_database_destroyDavid Bremner
Since most memory allocation is (ultimately) in the talloc context defined by a notmuch_database_t pointer, this gives a more complete view of memory still allocated at program shutdown. We also change the talloc report in notmuch.c to mode "a" to avoid clobbering the newly reported log.
2021-03-27lib: add NOTMUCH_STATUS_NO_DATABASEDavid Bremner
This will allow more precise return values from various open related functions.
2021-03-27lib: add missing status stringsDavid Bremner
2021-03-20lib/compact: enable split configDavid Bremner
This promotes _choose_xapian_path from static to extern linkage in order to share between open.cc and database.cc.
2021-03-20lib: support splitting mail from database location.David Bremner
Introduce a new configuration value for the mail root, and use it to locate mail messages in preference to the database.path (which previously implied the mail messages were also in this location. Initially only a subset of the CLI is tested in a split configuration. Further changes will be needed for the remainder of the CLI to work in split configurations.
2021-03-20lib: remove "path" from notmuch structDavid Bremner
This removes duplication between the struct element and the configuration string_map entry. Create a simple wrapper for setting the database path that makes sure the trailing / is stripped.
2021-03-18lib: support reopening databases for write access.David Bremner
In the future Xapian will apparently support this more conveniently for the cases other than READ_ONLY => READ_ONLY Conceptually this function seems to fit better in lib/open.cc; database.cc is still large enough that moving the function makes sense.
2021-03-18lib: publish API for notmuch_database_reopenDavid Bremner
Include the (currently unused) mode argument which will specify which mode to re-open the database in. Functionality and docs to be finalized in a followup commit.
2021-03-13lib: run uncrustifyuncrustify
This is the result of running $ uncrustify --replace --config ../devel/uncrustify.cfg *.c *.h *.cc in the lib directory
2021-02-06lib/database: move n_d_create* to open.ccDavid Bremner
This will help share code with n_d_open_with_config.
2021-02-06lib: split notmuch_database_compactDavid Bremner
The "back end" function takes an open notmuch database, which should know its own path (i.e. the path needs to be cached in the configuration data).
2020-12-23lib: factor out notmuch_database_open* related code to own fileDavid Bremner
Reduce the size of database.cc, and prepare for extending the database opening API
2020-12-23lib: factor out prefix related code to its own fileDavid Bremner
Reduce the size of database.cc, and limit the scope of prefix_table, make sure it's accessed via a well-defined internal API.
2020-12-23lib: factor out feature name related code.David Bremner
database.cc is uncomfortably large, and some of the static data structures do not need to be shared as much as they are. This is a somewhat small piece to factor out, but it will turn out to be helpful to further refactoring.
2020-07-28lib: replace use of static_cast for writable databasesDavid Bremner
static_cast is a bit tricky to understand and error prone, so add a second pointer to (potentially the same) Xapian database object that we know has the right subclass.
2020-07-28lib: encapsulate the use of notmuch_database_t field 'mode'David Bremner
The plan is to change the underlying representation.
2020-07-28lib: drop two gratuitous assignments to database modeDavid Bremner
I'm not sure what the point of modifying that right before destroying the object is. In a future commit I want to remove that element of the object, so simplify that task.
2020-07-22lib: rename _n_d_create to _n_d_find_or_createDavid Bremner
The error message and name were confusing when called in some "read only" context.
2020-07-22lib/n_d_needs_upgrade: handle error return from n_d_get_versionDavid Bremner
Also clarify documentation of error return from n_d_needs_upgrade.
2020-07-22lib/n_d_get_version: catch exceptions and clarify the APIDavid Bremner
notmuch_database_get_version previously returned 0 on some errors, but did not document this. Luckily 0 is not a valid database version.
2020-07-22lib: move deallocation of memory from n_d_close to n_d_destroyDavid Bremner
In order to mimic the "best effort" API of Xapian to provide information from a closed database when possible, do not destroy the Xapian database object too early. Because the pointer to a Xapian database is no longer nulled on close, introduce a flag to track whether the notmuch database is open or not.
2020-07-11lib: migrate from Xapian ValueRangeProcessor to RangeProcessorDavid Bremner
This will be mandatory as of Xapian 1.5. The API is also more consistent with the FieldProcessor API, which helps code re-use a bit. Note that this switches to using the built-in Xapian support for prefixes on ranges (i.e. deleted code at beginning of ParseTimeRangeProcessor::operator(), added prefix to constructor). Another side effect of the migration is that we are generating smaller queries, using one OP_VALUE_RANGE instead of an AND of two OP_VALUE_* queries.
2020-07-11lib: migrate to post Xapian 1.3.4 compact supportDavid Bremner
The old API was deprecated in Xapian 1.3.4 and (will be) removed in 1.5.0
2020-04-23build: drop support for xapian versions less than 1.4Tomi Ollila
Xapian 1.4 is over 3 years old now (1.4.0 released 2016-06-24), and 1.2 has been deprecated in Notmuch version 0.27 (2018-06-13). Xapian 1.4 supports compaction, field processors and retry locking; conditionals checking compaction and field processors were removed but user may want to disable retry locking at configure time so it is kept.
2019-06-14lib: run uncrustifyuncrustify
This is the result of running $ uncrustify --replace --config ../devel/uncrustify.cfg *.c *.h *.cc in the lib directory
2019-05-25lib/database: index user headers.David Bremner
This essentially involves calling _notmuch_message_gen_terms once for each user defined header.
2019-05-25lib: support user prefix names in term generationDavid Bremner
This should not change the indexing process yet as nothing calls _notmuch_message_gen_terms with a user prefix name. On the other hand, it should not break anything either. _notmuch_database_prefix does a linear walk of the list of (built-in) prefixes, followed by a logarithmic time search of the list of user prefixes. The latter is probably not really noticable.
2019-05-25lib: cache user prefixes in database objectDavid Bremner
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.
2019-05-25lib: setup user headers in query parserDavid Bremner
These tests will need to be updated if the Xapian query print/debug format changes.
2019-05-03gmime-cleanup: drop unused gmime #defines and simplify g_mime_init ()Daniel Kahn Gillmor
Several of these #defines were not actually used in the notmuch codebase any longer. And as of GMime 3.0, g_mime_init takes no arguments, so we can also drop the bogus RFC2047 argument that we were passing and then #defining away. signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-04-17lib: add 'body:' field, stop indexing headers twice.David Bremner
The new `body:` field (in Xapian terms) or prefix (in slightly sloppier notmuch) terms allows matching terms that occur only in the body. Unprefixed query terms should continue to match anywhere (header or body) in the message. This follows a suggestion of Olly Betts to use the facility (since Xapian 1.0.4) to add the same field with multiple prefixes. The double indexing of previous versions is thus replaced with a query time expension of unprefixed query terms to the various prefixed equivalent. Reindexing will be needed for 'body:' searches to work correctly; otherwise they will also match messages where the term occur in headers (demonstrated by the new tests in T530-upgrade.sh)
2019-03-31lib: update commentary about path/folder termsDavid Bremner
We missed this when we changed to binary fields.
2019-03-31lib: add clarification about the use of "prefix" in the docs.David Bremner
2019-03-31lib: drop comment about only indexing one file.David Bremner
Although the situation is complicated by the value fields (which are taken from a single file), this comment is now more false than true.
2018-05-07lib: add thread subqueries.David Bremner
This change allows queries of the form thread:{from:me} and thread:{from:jian} and not thread:{from:dave} This is still somewhat brute-force, but it's a big improvement over both the shell script solution and the previous proposal [1], because it does not build the whole thread structure just generate a query. A further potential optimization is to replace the calls to notmuch with more specialized Xapian code; in particular it's not likely that reading all of the message metadata is a win here. [1]: id:20170820213240.20526-1-david@tethera.net
2017-12-28Revert "lib: add thread subqueries."David Bremner
This reverts commit 4f5bbaf7e2cecfe5022ba4b28915cccfb7ccb12d.
2017-12-25lib: add thread subqueries.David Bremner
This change allows queries of the form thread:{from:me} and thread:{from:jian} and not thread:{from:dave} This is still somewhat brute-force, but it's a big improvement over both the shell script solution and the previous proposal [1], because it does not build the whole thread structure just generate a query. A further potential optimization is to replace the calls to notmuch with more specialized Xapian code; in particular it's not likely that reading all of the message metadata is a win here. [1]: id:20170820213240.20526-1-david@tethera.net
2017-10-20crypto: make shared crypto code behave library-likeDaniel Kahn Gillmor
If we're going to reuse the crypto code across both the library and the client, then it needs to report error states properly and not write to stderr.
2017-10-09lib: convert notmuch_bool_t to stdbool internallyJani Nikula
C99 stdbool turned 18 this year. There really is no reason to use our own, except in the library interface for backward compatibility. Convert the lib internally to stdbool.