[PATCH 0/5] Store message modification times in the DB

Thomas Jost schnouki at schnouki.net
Tue Dec 13 09:11:40 PST 2011


Hello world,

This is a patch series I've been working on for some time in order to be
able to sync my tags on several computers. I'm posting it now, but
please consider it as a RFC rather than something that is ready to be
pushed.

The basic idea is to the last time each message was modified, i.e. "the
message was added to the DB", "a tag was added" or "a tag was removed".

This mtime is accessible through a library function and in the JSON
output of "notmuch show". It is also searchable with the "mtime:" prefix
and with timestamp ranges, like for searching messages by date:

    notmuch search mtime:$(date +%s 2011-12-01)..$(date +%s)

This can then be used in scripts or helper programs to do incremental
dumps or tags synchronization. (I already have a script to do
incremental backups, but it needs some cleaning, and I'm still working
on something for sync'ing tags, but it's starting to work really well;
I'll post them later).

This can be seen as an alternative to David Bremner's jlog branch, but
with several differences:

+ no external dependency
+ everything is stored in the notmuch DB: atomicity for free!
- when a message is removed we lose everything about it, which makes the
  sync process more complicated
- for a human, it's harder to manipulate timestamps than log messages
- this can store much less data than a proper log system

On IRC amdragon suggested using a simple sequence number instead of a
timestamp. This would indeed eliminate the need for proper time
synchronization between computers one would want to keep in sync, and it
would reduce the risk of time-going-backward problems, but IMHO it would
cause more problems: no global clock --> no simple way to tell if DB #A
is more recent than DB #B.

So, here are the patches:
- first a little fix to the comments describing the DB schema (not
  specific to this patch series at all, I just noticed it when rebasing
  this series)
- the second commit adds the MTIME value to the database schema, and
  creates the functions used to update and access this value.
- the third commit makes the MTIME value searchable with a range syntax.
- the fourth commit adds the MTIME to the JSON output of "notmuch show".
- the fifth and last commit adds Message.get_mtime() to the Python
  bindings.

Please tell me what you think of this.

Best regards,
Thomas

Thomas Jost (5):
  Fix comments about what is stored in the database
  lib: Add a MTIME value to every mail document
  lib: Make MTIME values searchable
  show: include mtime in JSON output
  python: add get_mtime() to the Message class

 bindings/python/notmuch/message.py |   20 ++++++++++++++++++++
 lib/database-private.h             |    1 +
 lib/database.cc                    |   14 +++++++++++++-
 lib/message.cc                     |   32 ++++++++++++++++++++++++++++++++
 lib/notmuch-private.h              |    6 +++++-
 lib/notmuch.h                      |    4 ++++
 notmuch-show.c                     |    7 ++++---
 notmuch.1                          |   14 ++++++++++++--
 notmuch.c                          |   13 ++++++++++---
 9 files changed, 101 insertions(+), 10 deletions(-)

-- 
1.7.8



More information about the notmuch mailing list