[PATCH 2/2] lib: Allow synchronizing message changes with a separate database connection
Michael Forney
mforney at mforney.org
Mon Dec 10 22:54:53 PST 2012
The motivation for this patch is that in some cases, it is ideal to open
a read-only database, and only open the database as writable when we
need to make changes to a message. This way, we don't block other
programs to write to the database when we don't need to.
With the current system, in order to modify a tag of a message opened
read-only, I would have to find the message in a writable database with
my read-only message's ID, which would cause unnecessary reads from the
database, and seems overly complicated for a simple operation (replace
document).
---
bindings/go/src/notmuch/notmuch.go | 3 ++-
bindings/python/notmuch/message.py | 4 +++-
lib/database.cc | 7 +++++++
lib/notmuch.h | 26 +++++++++++++++++++++++---
4 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/bindings/go/src/notmuch/notmuch.go b/bindings/go/src/notmuch/notmuch.go
index 56eb710..85c6620 100644
--- a/bindings/go/src/notmuch/notmuch.go
+++ b/bindings/go/src/notmuch/notmuch.go
@@ -957,7 +957,8 @@ func (self *Message) RemoveAllTags() Status {
* notmuch_message_sync (message);
*
* This method only works if the database associated with 'message' was
- * opened in read-write mode.
+ * opened in read-write mode. If you wish make changes to a message
+ * opened with a read-only database, see notmuch_database_sync_message.
*
* Return value:
*
diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index 600c01e..b4f2d25 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -420,7 +420,9 @@ class Message(Python3StringMixIn):
msg.tags_to_maildir_flags()
This method only works if the database associated with 'message' was
- opened with NOTMUCH_DATABASE_MODE_READ_WRITE.
+ opened with NOTMUCH_DATABASE_MODE_READ_WRITE. If you wish make
+ changes to a message opened with a read-only database, see
+ notmuch_database_sync_message.
:param sync_maildir_flags: If notmuch configuration is set to do
this, add maildir flags corresponding to notmuch tags. See
diff --git a/lib/database.cc b/lib/database.cc
index 98ea789..a9718ab 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -388,6 +388,13 @@ notmuch_database_find_message (notmuch_database_t *notmuch,
}
}
+notmuch_status_t
+notmuch_database_sync_message (notmuch_database_t *notmuch,
+ notmuch_message_t *message)
+{
+ return _notmuch_message_sync_to_database (message, notmuch);
+}
+
/* Advance 'str' past any whitespace or RFC 822 comments. A comment is
* a (potentially nested) parenthesized sequence with '\' used to
* escape any character (including parentheses).
diff --git a/lib/notmuch.h b/lib/notmuch.h
index f6962ee..1570917 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -446,6 +446,23 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,
const char *filename,
notmuch_message_t **message);
+/* Synchronize the current state of 'message' into the given database.
+ *
+ * This is a more general version of notmuch_message_sync, allowing you
+ * to synchronize changes to a message opened with a read-only database
+ * into a writable database.
+ *
+ * Return value:
+ *
+ * NOTMUCH_STATUS_SUCCESS: Message successfully synchronized.
+ *
+ * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
+ * mode so message cannot be modified.
+ */
+notmuch_status_t
+notmuch_database_sync_message (notmuch_database_t *notmuch,
+ notmuch_message_t *message);
+
/* Return a list of all tags found in the database.
*
* This function creates a list of all tags found in the database. The
@@ -1040,7 +1057,8 @@ notmuch_message_get_tags (notmuch_message_t *message);
/* Add a tag to the given message.
*
* The changes to the message will not be committed into the database
- * until notmuch_message_sync is called.
+ * until notmuch_message_sync or notmuch_database_sync_message is
+ * called.
*
* Return value:
*
@@ -1057,7 +1075,8 @@ notmuch_message_add_tag (notmuch_message_t *message, const char *tag);
/* Remove a tag from the given message.
*
* The changes to the message will not be committed into the database
- * until notmuch_message_sync is called.
+ * until notmuch_message_sync or notmuch_database_sync_message is
+ * called.
*
* Return value:
*
@@ -1171,7 +1190,8 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message);
* notmuch_message_sync (message);
*
* This method only works if the database associated with 'message' was
- * opened in read-write mode.
+ * opened in read-write mode. If you wish make changes to a message
+ * opened with a read-only database, see notmuch_database_sync_message.
*
* Return value:
*
--
1.8.0
More information about the notmuch
mailing list