* if each flag has been initialized. */
unsigned long lazy_flags;
+ /* Message document modified since last sync */
+ notmuch_bool_t modified;
+
Xapian::Document doc;
Xapian::termcount termpos;
};
doc_id = _notmuch_database_generate_doc_id (notmuch);
} catch (const Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred creating message: %s\n",
+ _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred creating message: %s\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
*status_ret = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;
if (unlikely (filename == NULL))
return;
- message->message_file = _notmuch_message_file_open_ctx (message, filename);
+ message->message_file = _notmuch_message_file_open_ctx (
+ _notmuch_message_database (message), message, filename);
}
const char *
return talloc_strdup (message, value.c_str ());
} catch (Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred when reading header: %s\n",
+ _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading header: %s\n",
error.get_msg().c_str());
message->notmuch->exception_reported = TRUE;
return NULL;
try {
message->doc.remove_term ((*i));
+ message->modified = TRUE;
} catch (const Xapian::InvalidArgumentError) {
/* Ignore failure to remove non-existent term. */
}
_notmuch_message_clear_data (notmuch_message_t *message)
{
message->doc.set_data ("");
+ message->modified = TRUE;
}
static void
try {
value = message->doc.get_value (NOTMUCH_VALUE_TIMESTAMP);
} catch (Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred when reading date: %s\n",
+ _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading date: %s\n",
error.get_msg().c_str());
message->notmuch->exception_reported = TRUE;
return 0;
Xapian::sortable_serialise (time_value));
message->doc.add_value (NOTMUCH_VALUE_FROM, from);
message->doc.add_value (NOTMUCH_VALUE_SUBJECT, subject);
+ message->modified = TRUE;
+}
+
+/* Upgrade a message to support NOTMUCH_FEATURE_LAST_MOD. The caller
+ * must call _notmuch_message_sync. */
+void
+_notmuch_message_upgrade_last_mod (notmuch_message_t *message)
+{
+ /* _notmuch_message_sync will update the last modification
+ * revision; we just have to ask it to. */
+ message->modified = TRUE;
}
/* Synchronize changes made to message->doc out into the database. */
if (message->notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
return;
+ if (! message->modified)
+ return;
+
+ /* Update the last modification of this message. */
+ if (message->notmuch->features & NOTMUCH_FEATURE_LAST_MOD)
+ /* sortable_serialise gives a reasonably compact encoding,
+ * which directly translates to reduced IO when scanning the
+ * value stream. Since it's built for doubles, we only get 53
+ * effective bits, but that's still enough for the database to
+ * last a few centuries at 1 million revisions per second. */
+ message->doc.add_value (NOTMUCH_VALUE_LAST_MOD,
+ Xapian::sortable_serialise (
+ _notmuch_database_new_revision (
+ message->notmuch)));
+
db = static_cast <Xapian::WritableDatabase *> (message->notmuch->xapian_db);
db->replace_document (message->doc_id, message->doc);
+ message->modified = FALSE;
}
/* Delete a message document from the database. */
return NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG;
message->doc.add_term (term, 0);
+ message->modified = TRUE;
talloc_free (term);
try {
message->doc.remove_term (term);
+ message->modified = TRUE;
} catch (const Xapian::InvalidArgumentError) {
/* We'll let the philosopher's try to wrestle with the
* question of whether failing to remove that which was not
{
talloc_free (message);
}
+
+notmuch_database_t *
+_notmuch_message_database (notmuch_message_t *message)
+{
+ return message->notmuch;
+}