From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 4CF9E429E50 for ; Wed, 14 Dec 2011 16:43:47 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8+eauh1sgLjM for ; Wed, 14 Dec 2011 16:43:46 -0800 (PST) Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU [18.9.25.12]) by olra.theworths.org (Postfix) with ESMTP id 54301429E4E for ; Wed, 14 Dec 2011 16:43:46 -0800 (PST) X-AuditID: 1209190c-b7fad6d000000920-73-4ee942c0501e Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP id EF.42.02336.0C249EE4; Wed, 14 Dec 2011 19:43:44 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id pBF0hgFp027837; Wed, 14 Dec 2011 19:43:43 -0500 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id pBF0heQK009871 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Wed, 14 Dec 2011 19:43:42 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1RazRc-0001id-0C; Wed, 14 Dec 2011 19:45:08 -0500 Date: Wed, 14 Dec 2011 19:45:07 -0500 From: Austin Clements To: Thomas Jost Subject: Re: [PATCH 2/5] lib: Add a MTIME value to every mail document Message-ID: <20111215004507.GF2760@mit.edu> References: <1323796305-28789-1-git-send-email-schnouki@schnouki.net> <1323796305-28789-3-git-send-email-schnouki@schnouki.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1323796305-28789-3-git-send-email-schnouki@schnouki.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmleLIzCtJLcpLzFFi42IR4hRV1j3g9NLPoGMJp8X1mzOZLfb1+zsw eTxbdYvZY8qsuewBTFFcNimpOZllqUX6dglcGQ1bXjIVNOpVdO/9ydTA+Ei5i5GTQ0LAROL9 7snMELaYxIV769m6GLk4hAT2MUosetcP5WxglPjx/hErSJWQwEkmiftzDSESSxgl1i7cyA6S YBFQlXi45TAjiM0moCGxbf9yMFtEQF2iYf5uNhCbWUBa4tvvZiYQW1jATeLb9BtgNq+AtsSv pplMEEMbGSUmL5wDlRCUODnzCQtEs5bEjX8vgeIcYIOW/+MACXMCzZn+sBWsXFRARWLKyW1s ExiFZiHpnoWkexZC9wJG5lWMsim5Vbq5iZk5xanJusXJiXl5qUW6hnq5mSV6qSmlmxjBYS3J s4PxzUGlQ4wCHIxKPLwBh1/4CbEmlhVX5h5ilORgUhLlLbZ96SfEl5SfUpmRWJwRX1Sak1p8 iFGCg1lJhLdrL1A5b0piZVVqUT5MSpqDRUmct3rXQz8hgfTEktTs1NSC1CKYrAwHh5IErxIw foUEi1LTUyvSMnNKENJMHJwgw3mAhi9zBKrhLS5IzC3OTIfIn2JUlBLn5QVpFgBJZJTmwfXC 0s4rRnGgV4R5FUCqeIApC677FdBgJqDB28NAri4uSURISTUwLn1j4+o173W88bkjWztLDp6X rfzp4HlUYWeRStDPJrN2V+aJZ+I/Mqr2n9IU6i3+lJl7dFmzZlXLxKaidWdmLgxbVGnNb7g2 XbP249NXC7fPm/xE9M1n0672w+wSt5vfqfjwxkqnffu1aafp858Ce4/6e2p3/WZ5LBQ0/bLX ouVfgu9mbDitoMRSnJFoqMVcVJwIAHAzwR0WAwAA Cc: notmuch@notmuchmail.org X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Dec 2011 00:43:47 -0000 A few minor comments below. At a higher level, I'm curious what the tag synchronization protocol you're building on top of this is. I can't think of one that doesn't have race conditions, but maybe I'm not thinking about it right. Quoth Thomas Jost on Dec 13 at 6:11 pm: > This is a time_t value, similar to the message date (TIMESTAMP). It is first set > when the message is added to the database, and is then updated every time a tag > is added or removed. It can thus be used for doing incremental dumps of the > database or for synchronizing it between several computers. > > This value can be read freely (with notmuch_message_get_mtime()) but for now it > can't be set to an arbitrary value: it can only be set to "now" when updated. > There's no specific reason for this except that I don't really see a real use > case for setting it to an arbitrary value. > --- > lib/database.cc | 7 ++++++- > lib/message.cc | 32 ++++++++++++++++++++++++++++++++ > lib/notmuch-private.h | 6 +++++- > lib/notmuch.h | 4 ++++ > 4 files changed, 47 insertions(+), 2 deletions(-) > > diff --git a/lib/database.cc b/lib/database.cc > index 2025189..6dc6f73 100644 > --- a/lib/database.cc > +++ b/lib/database.cc > @@ -81,7 +81,7 @@ typedef struct { > * STRING is the name of a file within that > * directory for this mail message. > * > - * A mail document also has four values: > + * A mail document also has five values: > * > * TIMESTAMP: The time_t value corresponding to the message's > * Date header. > @@ -92,6 +92,9 @@ typedef struct { > * > * SUBJECT: The value of the "Subject" header > * > + * MTIME: The time_t value corresponding to the last time > + * a tag was added or removed on the message. > + * > * In addition, terms from the content of the message are added with > * "from", "to", "attachment", and "subject" prefixes for use by the > * user in searching. Similarly, terms from the path of the mail > @@ -1735,6 +1738,8 @@ notmuch_database_add_message (notmuch_database_t *notmuch, > date = notmuch_message_file_get_header (message_file, "date"); > _notmuch_message_set_header_values (message, date, from, subject); > > + _notmuch_message_update_mtime (message); Indentation. > + > _notmuch_message_index_file (message, filename); > } else { > ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID; > diff --git a/lib/message.cc b/lib/message.cc > index 0075425..0c98589 100644 > --- a/lib/message.cc > +++ b/lib/message.cc > @@ -830,6 +830,34 @@ _notmuch_message_set_header_values (notmuch_message_t *message, > message->doc.add_value (NOTMUCH_VALUE_SUBJECT, subject); > } > > +/* Get the message mtime, i.e. when it was added or the last time a tag was > + * added/removed. */ > +time_t > +notmuch_message_get_mtime (notmuch_message_t *message) > +{ > + std::string value; > + > + try { > + value = message->doc.get_value (NOTMUCH_VALUE_MTIME); > + } catch (Xapian::Error &error) { > + INTERNAL_ERROR ("Failed to read mtime value from document."); > + return 0; > + } For compatibility, this should handle the case when NOTMUCH_VALUE_MTIME is missing, probably by just returning 0. As it is, value will be an empty string and sortable_unserialise is undefined on strings that weren't produced by sortable_serialise. > + > + return Xapian::sortable_unserialise (value); > +} > + > +/* Set the message mtime to "now". */ > +void > +_notmuch_message_update_mtime (notmuch_message_t *message) > +{ > + time_t time_value; > + > + time_value = time (NULL); > + message->doc.add_value (NOTMUCH_VALUE_MTIME, > + Xapian::sortable_serialise (time_value)); Indentation. > +} > + > /* Synchronize changes made to message->doc out into the database. */ > void > _notmuch_message_sync (notmuch_message_t *message) > @@ -994,6 +1022,8 @@ notmuch_message_add_tag (notmuch_message_t *message, const char *tag) > private_status); > } > > + _notmuch_message_update_mtime (message); > + > if (! message->frozen) > _notmuch_message_sync (message); > > @@ -1022,6 +1052,8 @@ notmuch_message_remove_tag (notmuch_message_t *message, const char *tag) > private_status); > } > > + _notmuch_message_update_mtime (message); > + > if (! message->frozen) > _notmuch_message_sync (message); > > diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h > index 60a932f..9859872 100644 > --- a/lib/notmuch-private.h > +++ b/lib/notmuch-private.h > @@ -95,7 +95,8 @@ typedef enum { > NOTMUCH_VALUE_TIMESTAMP = 0, > NOTMUCH_VALUE_MESSAGE_ID, > NOTMUCH_VALUE_FROM, > - NOTMUCH_VALUE_SUBJECT > + NOTMUCH_VALUE_SUBJECT, > + NOTMUCH_VALUE_MTIME > } notmuch_value_t; > > /* Xapian (with flint backend) complains if we provide a term longer > @@ -276,6 +277,9 @@ _notmuch_message_set_header_values (notmuch_message_t *message, > const char *from, > const char *subject); > void > +_notmuch_message_update_mtime (notmuch_message_t *message); > + > +void > _notmuch_message_sync (notmuch_message_t *message); > > notmuch_status_t > diff --git a/lib/notmuch.h b/lib/notmuch.h > index 9f23a10..643ebce 100644 > --- a/lib/notmuch.h > +++ b/lib/notmuch.h > @@ -910,6 +910,10 @@ notmuch_message_set_flag (notmuch_message_t *message, > time_t > notmuch_message_get_date (notmuch_message_t *message); > > +/* Get the mtime of 'message' as a time_t value. */ > +time_t > +notmuch_message_get_mtime (notmuch_message_t *message); > + > /* Get the value of the specified header from 'message'. > * > * The value will be read from the actual message file, not from the