aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/database.cc
Commit message (Collapse)AuthorAge
...
* Fix comments about what is stored in the databaseGravatar Thomas Jost2011-12-23
| | | | | | Commit 567bcbc2 introduced two new values for each message (content of the "From" and "Subject" headers), but the comments about the database schema had not been updated accordingly.
* notmuch: Quiet buildbot warnings.Gravatar David Edmondson2011-12-21
| | | | | Cast away the result of various *write functions. Provide a default value for some variables to avoid "use before set" warnings.
* lib: call g_type_init from notmuch_database_openGravatar David Bremner2011-12-04
| | | | | We want to make sure g_type_init is called before any GObject functionality is used.
* Store "from" and "subject" headers in the database.Gravatar Austin Clements2011-11-14
| | | | | | | | | | | | | | This is a rebase and cleanup of Istvan Marko's patch from id:m3pqnj2j7a.fsf@zsu.kismala.com Search retrieves these headers for every message in the search results. Previously, this required opening and parsing every message file. Storing them directly in the database significantly reduces IO and computation, speeding up search by between 50% and 10X. Taking full advantage of this requires a database rebuild, but it will fall back to the old behavior for messages that do not have headers stored in the database.
* lib/database.cc: use flush Xapian method instead of commitGravatar David Bremner2011-11-02
| | | | | | | Apparently the method was renamed in Xapian 1.1.0 but the old method name will stay around for a while. It seems better to stick with the old name to make notmuch compile with older versions of Xapian, at least for now.
* xutil.c: remove duplicate copies, create new library libutil.a to contain xutil.Gravatar David Bremner2011-10-30
| | | | | | | We keep the lib/xutil.c version. As a consequence, also factor out _internal_error and associated macros. It might be overkill to make a new file error_util.c for this, but _internal_error does not really belong in database.cc.
* lib: make find_message{,by_filename) report errorsGravatar Ali Polatel2011-10-04
| | | | | | | | | | | | | | | | Previously, the functions notmuch_database_find_message() and notmuch_database_find_message_by_filename() functions did not properly report error condition to the library user. For more information, read the thread on the notmuch mailing list starting with my mail "id:871uv2unfd.fsf@gmail.com" Make these functions accept a pointer to 'notmuch_message_t' as argument and return notmuch_status_t which may be used to check for any error condition. restore: Modify for the new notmuch_database_find_message() new: Modify for the new notmuch_database_find_message_by_filename()
* lib: destroy message object after message removalGravatar Ali Polatel2011-10-04
| | | | | notmuch_database_remove_message() must call notmuch_message_destroy() once it is done handling message removal.
* lib: Wrap notmuch_database_add_message in an atomic section.Gravatar Austin Clements2011-09-24
| | | | | | | | Adding a message may involve changes to multiple database documents, and thus needs to be done in a transaction. This makes add_message (and, I think, the whole library) atomicity-safe: library callers only needs to use atomic sections if they needs atomicity across multiple library calls.
* lib: Add an API to find a message by filename.Gravatar Austin Clements2011-09-24
| | | | | | | | | notmuch_database_find_message_by_filename is mostly stolen from notmuch_database_remove_message, so this patch also vastly simplfies the latter using the former. This API is also useful in its own right and will be used in a later patch for eager maildir flag synchronization.
* lib: Remove message document directly after removing the last file name.Gravatar Austin Clements2011-09-23
| | | | | | | | | | | | Previously, notmuch_database_remove_message would remove the message file name, sync the change to the message document, re-find the message document, and then delete it if there were no more file names. An interruption after sync'ing would result in a file-name-less, permanently un-removable zombie message that would produce errors and odd results in searches. We could wrap this in an atomic section, but it's much simpler to eliminate the round-about approach and just delete the message document instead of sync'ing it if we removed the last filename.
* lib: Add support for nested atomic sections.Gravatar Austin Clements2011-09-23
| | | | | | | notmuch_database_t now keeps a nesting count and we only start a transaction or commit for the outermost atomic section. Introduces a new error, NOTMUCH_STATUS_UNBALANCED_ATOMIC.
* lib: Add notmuch_database_{begin,end}_atomic.Gravatar Austin Clements2011-09-23
| | | | | | These operations translate into non-flushed Xapian transactions, allowing arbitrary groups of database operations to be performed atomically.
* fix sum moar typos [comments in source code]Gravatar Pieter Praet2011-06-23
| | | | | | | | | | Various typo fixes in comments within the source code. Signed-off-by: Pieter Praet <pieter@praet.org> Edited-by: Carl Worth <cworth@cworth.org> Restricted to just source-code comments, (and fixed fix of "descriptios" to "descriptors" rather than "descriptions").
* Add a generic function to get a list of terms with some prefix.Gravatar Austin Clements2011-03-21
| | | | | | Replace _notmuch_convert_tags with this and simplify _create_filenames_for_terms_with_prefix. This will also come in handy shortly to get the message file name list.
* Implement an internal generic string list and use it.Gravatar Austin Clements2011-03-21
| | | | | | | | | | | | This replaces the guts of the filename list and tag list, making those interfaces simple iterators over the generic string list. The directory, message filename, and tags-related code now build generic string lists and then wraps them in specific iterators. The real wins come in later patches, when we use these for even more generic functionality. As a nice side-effect, this also eliminates the annoying dependency on GList in the tag list.
* Add support for folder-based searching.Gravatar Carl Worth2011-01-15
| | | | | | | | A new "folder:" prefix in the query string can now be used to match the directories in which mail files are stored. The addition of this feature causes the recently added search-by-folder tests to now pass.
* Tighten up a memory allocation.Gravatar Carl Worth2011-01-15
| | | | | | Using the local talloc context ensures that the memory we are using here will be freed shortly, (rather than hanging on for a long time with the notmuch database object).
* lib: Remove the notion of TAGS_INVALIDGravatar Carl Worth2010-11-11
| | | | | | | | This rather ugly hack was recently obviated by the removal of the notmuch_database_set_maildir_sync function. Now, clients must make explicit calls to do any syncrhonization between maildir flags and tags. So the library no longer needs to worry about doing inconsistent synchronization while a message is only partially added.
* lib: Rework interface for maildir_flags synchronizationGravatar Carl Worth2010-11-11
| | | | | | | | | | | | | Instead of having an API for setting a library-wide flag for synchronization (notmuch_database_set_maildir_sync) we instead implement maildir synchronization with two new library functions: notmuch_message_maildir_flags_to_tags and notmuch_message_tags_to_maildir_flags These functions are nicely documented here, (though the implementation does not quite match the documentation yet---as plainly evidenced by the current results of the test suite).
* Make maildir synchronization configurableGravatar Michal Sojka2010-11-10
| | | | | | | This adds group [maildir] and key 'synchronize_flags' to the configuration file. Its value enables (true) or diables (false) the synchronization between notmuch tags and maildir flags. By default, the synchronization is disabled.
* Maildir synchronizationGravatar Michal Sojka2010-11-10
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch allows bi-directional synchronization between maildir flags and certain tags. The flag-to-tag mapping is defined by flag2tag array. The synchronization works this way: 1) Whenever notmuch new is executed, the following happens: o New messages are tagged with configured new_tags. o For new or renamed messages with maildir info present in the file name, the tags defined in flag2tag are either added or removed depending on the flags from the file name. 2) Whenever notmuch tag (or notmuch restore) is executed, a new set of flags based on the tags is constructed for every message and a new file name is prepared based on the old file name but with the new flags. If the flags differs and the old message was in 'new' directory then this is replaced with 'cur' in the new file name. If the new and old file names differ, the file is renamed and notmuch database is updated accordingly. The rename happens before the database is updated. In case of crash between rename and database update, the next run of notmuch new brings the database in sync with the mail store again.
* lib: Return added message even if it already was in the databaseGravatar Michal Sojka2010-11-10
|
* lib: Eliminate some redundant includes of xapian.hGravatar Carl Worth2010-11-01
| | | | | Most files including this already include database-private.h which includes xapian.h already.
* lib: Add some missing static qualifiers.Gravatar Carl Worth2010-11-01
| | | | | | These various functions and data are all used only locally, so should be marked static. Ensuring we get these right will avoid us accidentally leaking unintended symbols through the library interface.
* lib: Fix use-after-free bug.Gravatar Carl Worth2010-09-20
| | | | | | | Thanks to the new git-based test suite, it's easy to run the whole test suite in valgrind, (simply "make test OPTIONS="--valgrind"), and doing so showed this obvious use-after-free bug, (triggered by the thread-order tests).
* Add support (and tests) for messages with really long message IDs.Gravatar Carl Worth2010-06-04
| | | | | | | | | | | | | | | | | | | | | | | Scott Henson reported an internal error that occurred when he tried to add a message that referenced another message with a message ID well over 300 characters in length. The bug here was running into a Xapian limit for the length of metadata key names, (which is even more restrictive than the Xapian limit for the length of terms). We fix this by noticing long message ID values and instead using a message ID of the form "notmuch-sha1-<sha1_sum_of_message_id>". That is, we use SHA1 to generate a compressed, (but still unique), version of the message ID. We add support to the test suite to exercise this fix. The tests add a message referencing the long message ID, then add the message with the long message ID, then finally add another message referencing the long ID. Each of these tests exercise different code paths where the special handling is implemented. A final test ensures that all three messages are stitched together into a single thread---guaranteeing that the three code paths all act consistently.
* Avoid database corruption by not adding partially-constructed mail documents.Gravatar Carl Worth2010-06-04
| | | | | | | | | | | | | | | | | Previously we were using Xapian's add_document to allocate document ID values for notmuch_message_t objects. This had the drawback of adding a partially constructed mail document to the database. If notmuch was subsequently interrupted before fully populating this document, then later runs would be quite confused when seeing the partial documents. There are reports from the wild of people hitting internal errors of the form "Message ... has no thread ID" for example, (which is currently an unrecoverable error). We fix this by manually allocating document IDs without adding documents. With this change, we never call Xapian's add_document method, but only replace_document with either the current document ID of a message or a new one that we have allocated.
* lib: Audit all notmuch_database call for Xapian exception handling.Gravatar Carl Worth2010-04-24
| | | | | | Our current approach is for top-level entry poitns in the library to have try/catch blocks that catch any Xapian exception and print a message. Add a few missing blocks and fix up the documentation.
* lib: Remove condition regarding a NULL parent_thread_id.Gravatar Carl Worth2010-04-12
| | | | | A recent change guaranteed that a message ID can never be resolved to a NULL thread ID, so we don't need this extra case.
* lib: Always add reference terms to the database.Gravatar Carl Worth2010-04-12
| | | | | | | | Previously, we were only adding the reference terms for cases where the referenced message did not yet exist in the database. For thread presentation, it's useful to have the connection information provided by the references, even when the messages are present. So add this term unconditionally.
* lib: Document the metadata stored within the Xapian database.Gravatar Carl Worth2010-04-12
| | | | | We are currently storing "version", "last_thread_id", and "thread_id_*" values so document how each of these are used.
* lib: Fix line-wrapping in _notmuch_database_link_message.Gravatar Carl Worth2010-04-12
| | | | | | This function had some excessively long lines due to nested expressions. It's simple enough to un-nest these and have readable line lengths.
* lib: Fix internal documentation of _notmuch_database_link_messageGravatar Carl Worth2010-04-12
| | | | | | This function was recently modified, (to include a metadata lookup for a message's thread ID before looking for parent/child thread IDs), but the documentation wasn't updated. Fix that.
* lib: Simplify code flow in _resolve_message_id_to_thread_idGravatar Carl Worth2010-04-12
| | | | | | There are two primary cases in this function, (the message exists in the database or it does not). Previously the code for these two cases was split and intermingled with goto-spaghetti connections.
* lib: Fix internal documentation of _resolve_message_id_to_thread_idGravatar Carl Worth2010-04-12
| | | | | We no longer return NULL, but instead generate a new thread ID for messages that we haven't seen yet.
* Store thread ids for messages that we haven't seen yetGravatar James Westby2010-04-12
| | | | | | | | | | | | | | | | This allows us to thread messages even when we receive them out of order, or never receive the root. The thread ids for messages that aren't present but are referred to are stored as metadata in the database and then retrieved if we ever get that message. When determining the thread id for a message we also check for this metadata so that we can thread descendants of a message together before we receive it. Edited by Carl Worth <cworth@cworth.org>: Split this portion of the commit from the earlier-applied portion adding test cases.
* Add is:<tag> as a synonym for tag:<tag> in search terms.Gravatar Carl Worth2010-03-09
| | | | | I like the readability of this, it provides compatibility with people trained in this syntax by sup, and it even saves one character.
* lib: Rename iterator functions to prepare for reverse iteration.Gravatar Carl Worth2010-03-09
| | | | | | | | We rename 'has_more' to 'valid' so that it can function whether iterating in a forward or reverse direction. We also rename 'advance' to 'move_to_next' to setup parallel naming with the proposed functions 'move_to_first', 'move_to_last', and 'move_to_previous'.
* Fix printf for when uint64_t != unsigned long long intGravatar Carl Worth2010-02-09
| | | | | | | | Thanks to Michal Sojka <sojkam1@fel.cvut.cz> for pointing out the correct fix, which I verified in the freely-available WG14/N1124 draft (from the C99 working group) which is available here: http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf
* Switch from random to sequential thread identifiers.Gravatar Carl Worth2010-02-09
| | | | | | | | | | | | | The sequential identifiers have the advantage of being guaranteed to be unique (until we overflow a 64-bit unsigned integer), and also take up half as much space in the "notmuch search" output (16 columns rather than 32). This change also has the side effect of fixing a bug where notmuch could block on /dev/random at startup (waiting for some entropy to appear). This bug was hit hard by the test suite, (which could easily exhaust the available entropy on common systems---resulting in large delays of the test suite).
* notmuch new: Print upgrade progress report as a percentage.Gravatar Carl Worth2010-01-09
| | | | | | | | | | | | Previously we were printing a number of messages upgraded so far. The original motivation for this was to accurately reflect the fact that there are two passes, (so each message is processed twice and it's not accurate to represent with a single count). But as it turns out, the second pass takes zero time (relatively speaking) so we're still not accounting for it. If nothing else, the percentage-based reporting makes for a cleaner API for the progress_notify function.
* lib: Split the database upgrade into two phases for safer operation.Gravatar Carl Worth2010-01-09
| | | | | | | | | The first phase copies data from the old format to the new format without deleting anything. This allows an old notmuch to still use the database if the upgrade process gets interrupted. The second phase performs the deletion (after updating the database version number). If the second phase is interrupted, there will be some unused data in the database, but it shouldn't cause any actual harm.
* lib: Delete stale timestamp documents during database upgrade.Gravatar Carl Worth2010-01-08
| | | | | Once we move the timestamp to the new directory document, we don't need the old one anymore.
* notmuch new: Fix progress notification on database upgrade.Gravatar Carl Worth2010-01-07
| | | | | This was firing continuously rather than just once per second as intended.
* lib: Implement versioning in the database and provide upgrade function.Gravatar Carl Worth2010-01-07
| | | | | | | | | | | | | | | | | | | | | | | | The recent support for renames in the database is our first time (since notmuch has had more than a single user) that we have a database format change. To support smooth upgrades we now encode a database format version number in the Xapian metadata. Going forward notmuch will emit a warning if used to read from a database with a newer version than it natively supports, and will refuse to write to a database with a newer version. The library also provides functions to query the database format version: notmuch_database_get_version to ask if notmuch wants a newer version than that: notmuch_database_needs_upgrade and a function to actually perform that upgrade: notmuch_database_upgrade
* Prefer READ_ONLY consistently over READONLY.Gravatar Carl Worth2010-01-07
| | | | | | Previously we had NOTMUCH_DATABASE_MODE_READ_ONLY but NOTMUCH_STATUS_READONLY_DATABASE which was ugly and confusing. Rename the latter to NOTMUCH_STATUS_READ_ONLY_DATABASE for consistency.
* lib: Consolidate checks for read-only database.Gravatar Carl Worth2010-01-07
| | | | | | | | | | | Previously, many checks were deep in the library just before a cast operation. These have now been replaced with internal errors and new checks have instead been added at the beginning of all top-levelentry points requiring a read-write database. The new checks now also use a single function for checking and printing the error message. This will give us a convenient location to extend the check, (such as based on database version as well).
* lib: Clarify internal documentation of _notmuch_database_filename_to_direntryGravatar Carl Worth2010-01-07
| | | | | | | The original wording made it sound like this function was just doing some string manipulation. But this function actually creates new directory documents as a side effect. So make that explicit in its documentation.
* lib: Indicate whether notmuch_database_remove_message removed anything.Gravatar Carl Worth2010-01-06
| | | | | | | | Similar to the return value of notmuch_database_add_message, we now enhance the return value of notmuch_database_remove_message to indicate whether the message document was entirely removed (SUCCESS) or whether only this filename was removed and the document exists under other filenamed (DUPLICATE_MESSAGE_ID).