Re: [PATCH 6/7] emacs: hello: add highlight newly arrived messages option

Subject: Re: [PATCH 6/7] emacs: hello: add highlight newly arrived messages option

Date: Mon, 12 May 2014 16:33:47 +0100

To: David Edmondson, notmuch@notmuchmail.org

Cc:

From: Mark Walters


On Mon, 12 May 2014, David Edmondson <dme@dme.org> wrote:
> On Sun, May 11 2014, Mark Walters wrote:
>> This adds a function that highlights searches which have newly arrived
>> messages (ones which arrived since the previous refresh of
>> notmuch-hello). It does that by getting a full list of matching
>> message ids and checking whether any new messages have appeared. Thus
>> it will be slow on large saved searches.
>> ---
>>  emacs/notmuch-hello.el |   21 +++++++++++++++++++++
>>  1 file changed, 21 insertions(+)
>>
>> diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
>> index 28e16be..265b879 100644
>> --- a/emacs/notmuch-hello.el
>> +++ b/emacs/notmuch-hello.el
>> @@ -96,6 +96,8 @@ (define-widget 'notmuch-saved-search-plist 'list
>>  				    (const :tag "Default (messages)" nil)
>>  				    (function-item :tag "messages/threads"
>>  						   notmuch-hello-display-count-threads-and-messages)
>> +				    (function-item :tag "highlight newly arrived messages"
>> +						   notmuch-hello-display-new-messages)
>>  				    function)))))
>>  
>>  (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")
>> @@ -507,6 +509,25 @@ (defun notmuch-hello-display-count-threads-and-messages (&rest args)
>>  			  (notmuch-hello-nice-number threads))))
>>      (plist-put current :count display)))
>>  
>> +(defun notmuch-hello-display-new-messages (&rest args)
>> +  "Highlight saved searches which have new messages.
>> +
>> +New messages are ones which have appeared since the last time
>> +notmuch hello was refreshed. This will be slow on large queries."
>> +  (let* ((current (plist-get args :current))
>> +	 (old (plist-get args :old))
>> +	 (query (plist-get current :query))
>> +	 (name (plist-get current :name))
>> +	 (new-list (notmuch-call-notmuch-sexp "search"
>> +					      "--output=messages"
>> +					      "--format=sexp"
>> +					      query))
>> +	 (old-list (plist-get old :message-list)))
>> +    (unless (subsetp new-list old-list :test 'equal)
>> +      (plist-put current :name (propertize name 'face '(:foreground "red"))))
>> +    (plist-put current :count (notmuch-hello-nice-number (length new-list)))
>> +    (plist-put current :message-list new-list)))
>
> I wonder if it would be better to store a hash value derived from the
> message list rather than the list itself. The list could be large.

My view was that the list was OK as a user would be foolish to set this
for any large queries anyway (as the query itself would be too
slow). Also, a hash itself wouldn't get the effect I want as I do want
to be to test "subset" for the two lists (as I don't care about messages
no longer matching, only new messages that do match: think inbox type
things) 

I could store the hash of the message-id. That might save a substantial
chunk on storage (eg 40 byte message if to 4byte hash or something)

More generally, it is not clear to me whether we want to make it easy
for a user to cause notmuch-hello to be very slow. Perhaps we need a
timing for each display-function. If any one takes over 0.5s then we can
report it to the user!

Best wishes

Mark






>
>> +
>>  (defun notmuch-hello-batch-message-count (elem-plist options)
>>    "Update the message count for a saved search.
>>  
>> -- 
>> 1.7.10.4
>>
>> _______________________________________________
>> notmuch mailing list
>> notmuch@notmuchmail.org
>> http://notmuchmail.org/mailman/listinfo/notmuch

Thread: