Re: [PATCH v4 08/16] reorganize indexing of multipart/signed and multipart/encrypted
[notmuch-archives.git] / fd / cf86b4c70de87b31e52d7b02a9dcc6a27ad146
1 Return-Path: <aaronecay@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 1B572431FD0\r
6         for <notmuch@notmuchmail.org>; Fri, 30 Dec 2011 11:21:37 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id 4Ung7nFkOffl for <notmuch@notmuchmail.org>;\r
17         Fri, 30 Dec 2011 11:21:36 -0800 (PST)\r
18 Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com\r
19         [209.85.216.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 25CF9431FB6\r
22         for <notmuch@notmuchmail.org>; Fri, 30 Dec 2011 11:21:36 -0800 (PST)\r
23 Received: by qcha6 with SMTP id a6so10926363qch.26\r
24         for <notmuch@notmuchmail.org>; Fri, 30 Dec 2011 11:21:35 -0800 (PST)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
26         h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
27         :mime-version:content-type:content-transfer-encoding;\r
28         bh=eLNsZoQdbyC+rNy7SA8Zlys2EmuyV4xuFTX4veog434=;\r
29         b=RH3swbhzSQGVGNXlPtsub3Xnn3HSzSiITKsFsidXGIdVmWS3iUkp8YzVdXDv6KcYpP\r
30         bR1NXDPD5IZrrnuwarPKFd8AHWDmVj4TDgDjGtxi459O+MDW8baqzUtO8GgQSjzCO3NZ\r
31         QTZuYZevNNeimTSlPyRNawjc8x2ZZd015bYhI=\r
32 Received: by 10.229.78.163 with SMTP id l35mr11757544qck.32.1325272895448;\r
33         Fri, 30 Dec 2011 11:21:35 -0800 (PST)\r
34 Received: from localhost (24-158-179-191.dhcp.jcsn.tn.charter.com.\r
35         [24.158.179.191])\r
36         by mx.google.com with ESMTPS id df3sm74088306qab.6.2011.12.30.11.21.33\r
37         (version=TLSv1/SSLv3 cipher=OTHER);\r
38         Fri, 30 Dec 2011 11:21:34 -0800 (PST)\r
39 From: Aaron Ecay <aaronecay@gmail.com>\r
40 To: David Edmondson <dme@dme.org>, Daniel Schoepe <daniel@schoepe.org>,\r
41         James Vasile <james@hackervisions.org>, notmuch@notmuchmail.org\r
42 Subject: Re: [notmuch] [PATCH] Calls to notmuch get queued and executed\r
43         asynchronously.\r
44 In-Reply-To: <cun4nwi8h7i.fsf@hotblack-desiato.hh.sledj.net>\r
45 References: <87vddnlxos.wl%james@hackervisions.org>\r
46         <87wrbykr13.fsf@gilead.invalid>\r
47         <cun4nwi8h7i.fsf@hotblack-desiato.hh.sledj.net>\r
48 User-Agent: Notmuch/0.10.1+56~gd709fd6 (http://notmuchmail.org)\r
49         Emacs/24.0.92.3 (i386-apple-darwin10.8.0)\r
50 Date: Fri, 30 Dec 2011 14:21:31 -0500\r
51 Message-ID: <m2fwg1uapw.fsf@gmail.com>\r
52 MIME-Version: 1.0\r
53 Content-Type: text/plain; charset=utf-8\r
54 Content-Transfer-Encoding: quoted-printable\r
55 X-BeenThere: notmuch@notmuchmail.org\r
56 X-Mailman-Version: 2.1.13\r
57 Precedence: list\r
58 List-Id: "Use and development of the notmuch mail system."\r
59         <notmuch.notmuchmail.org>\r
60 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
62 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
63 List-Post: <mailto:notmuch@notmuchmail.org>\r
64 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
65 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
67 X-List-Received-Date: Fri, 30 Dec 2011 19:21:37 -0000\r
68 \r
69 On Fri, 30 Dec 2011 10:52:17 +0000, David Edmondson <dme@dme.org> wrote:\r
70 > > I discovered this patch a while ago and it almost applies cleanly (the\r
71 > > conflicts are easy to fix though) and it has made the emacs UI for\r
72 > > notmuch _much_ more responsive and enjoyable for me.\r
73 \r
74 This is definitely true for me as well.  So much so that I reinvented\r
75 this patch from scratch a couple of weeks ago.  (As Picasso said, good\r
76 artists copy, great artists steal.)\r
77 \r
78 > > As discussed on IRC, issues such as where to handle retries in case\r
79 > > the database is locked should probably be handled in the notmuch\r
80 > > binary instead of each UI.\r
81 \r
82 Hmm.  When my implementation detects that it cannot get the DB lock\r
83 after trying several times (up to ~2 mins of waiting), it stops\r
84 trying but continues to queue up operations.  The user can then\r
85 manually restart the queue.  This isn=E2=80=99t a principled solution, but\r
86 it avoids losing tagging operations from emacs while a long-running\r
87 process has the DB locked.  (My original motivation for writing the\r
88 patch was actually that my new-mail script sometimes holds the DB\r
89 lock when I am trying to read mail, leading to emacs errors and\r
90 dropped tagging operations.  The speedup was a welcome side effect.)\r
91 \r
92 I haven=E2=80=99t had a chance to carefully look at the patch you found, so=\r
93  IDK\r
94 what its behavior would be in this case.\r
95 \r
96 (The other thing that I dislike about the patch you found is that it\r
97 uses a call to the =E2=80=9Csleep=E2=80=9D command to wait, rather than usi=\r
98 ng built-in\r
99 emacs functionality.)\r
100 \r
101 > It would be good to have an updated version of this patch if it is still\r
102 > considered useful, though I don't suffer particularly from lag in the\r
103 > emacs UI.\r
104 \r
105 The emacs UI has small delays, which dropped away when I applied my\r
106 version of this patch.  After being conditioned to expect them, I was\r
107 surprised to find how much faster everything seemed.  My hardware is old\r
108 but not ancient (5.5 year old Macbook; I suspect the bottleneck for\r
109 notmuch is the 5400rpm HDD).  Depending on your setup, you too might be\r
110 pleasantly surprised.\r
111 \r
112 The test suite is borked on OS X and I don=E2=80=99t have access to a linux\r
113 machine while traveling.  I was planning on sending my patch in early\r
114 Jan. when I had a chance to verify it under the test suite (probably\r
115 requiring some changes to the emacs test library to make it async-safe).\r
116 I also haven=E2=80=99t tested the patch on Emacs versions older than 24 =E2=\r
117 =80=93 but I\r
118 don=E2=80=99t think there are any impediments to compatibility with v.23 (n=\r
119 ot\r
120 sure about earlier versions).\r
121 \r
122 Since there is interest, I=E2=80=99ll go ahead and send it now with all the\r
123 usual caveats about code under development.  I have been using the patch\r
124 for a couple of weeks without problems, though.  Daniel, if you want to\r
125 un-conflict (and squash) the patches from James that might be useful, at\r
126 least to compare the two approaches.\r
127 \r
128 Aaron\r
129 \r
130 -----cut-here-----\r
131 \r
132 >From f0a0fe04254d9b5e17c873b293c6a5a270cb909a Mon Sep 17 00:00:00 2001\r
133 From: Aaron Ecay <aaronecay@gmail.com>\r
134 Date: Mon, 19 Dec 2011 12:14:31 -0500\r
135 Subject: [PATCH] [emacs] add async tagging support\r
136 \r
137 still a WIP\r
138 ---\r
139  emacs/notmuch.el |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++=\r
140 +++-\r
141  1 files changed, 54 insertions(+), 1 deletions(-)\r
142 \r
143 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
144 index fde2377..ca077c2 100644\r
145 --- a/emacs/notmuch.el\r
146 +++ b/emacs/notmuch.el\r
147 @@ -446,6 +446,59 @@ Complete list of currently available key bindings:\r
148    (let ((message-id (notmuch-search-find-thread-id)))\r
149      (notmuch-mua-new-reply message-id prompt-for-sender)))\r
150 =20\r
151 +(defvar notmuch-process-queue nil\r
152 +  "Queue of pending notmuch tag operations.\r
153 +\r
154 +Each entry in the queue is a list of strings, which are arguments\r
155 +to be passed to the notmuch command.")\r
156 +\r
157 +(defvar notmuch-process-current-command nil\r
158 +  "The currently executing notmuch command arguments")\r
159 +\r
160 +(defvar notmuch-process-wait-time 1.0\r
161 +  "How long to wait for the db lock, in seconds.")\r
162 +\r
163 +(defvar notmuch-process-error nil)\r
164 +\r
165 +(defun notmuch-process-restart-queue ()\r
166 +  (interactive)\r
167 +  (setq notmuch-process-error nil)\r
168 +  (notmuch-process-kick-queue))\r
169 +\r
170 +(defun notmuch-process-kick-queue ()\r
171 +  (when notmuch-process-error\r
172 +    ;; TODO: better error msg, tell how to manually kick\r
173 +    (error "Notmuch couldn't get the DB lock after trying for more than a =\r
174 minute."))\r
175 +  (when (and notmuch-process-queue\r
176 +            (memq (process-status "notmuch") '(exit nil)))\r
177 +    (let ((args (car notmuch-process-queue))\r
178 +         proc)\r
179 +      (setq notmuch-process-queue (cdr notmuch-process-queue)\r
180 +           notmuch-process-current-command args\r
181 +           proc (apply #'start-process "notmuch"\r
182 +                       (get-buffer-create "*Notmuch output*")\r
183 +                       notmuch-command args))\r
184 +      (set-process-sentinel proc #'notmuch-process-sentinel))))\r
185 +\r
186 +(defun notmuch-process-sentinel (proc status)\r
187 +  (if (equal status "finished\n")\r
188 +      (progn\r
189 +       (setq notmuch-process-wait-time 1.0\r
190 +             notmuch-process-current-command nil)\r
191 +       (notmuch-process-kick-queue))\r
192 +    (setq notmuch-process-wait-time (* 2 notmuch-process-wait-time)\r
193 +         notmuch-process-queue (cons notmuch-process-current-command\r
194 +                                     notmuch-process-queue))\r
195 +    (if (<=3D notmuch-process-wait-time 64)\r
196 +       (progn\r
197 +         (run-at-time notmuch-process-wait-time nil\r
198 +                      #'notmuch-process-kick-queue))\r
199 +      (setq notmuch-process-error t))))\r
200 +\r
201 +(defun notmuch-process-queue-command (&rest args)\r
202 +  (setq notmuch-process-queue (append notmuch-process-queue (list args)))\r
203 +  (notmuch-process-kick-queue))\r
204 +\r
205  (defun notmuch-call-notmuch-process (&rest args)\r
206    "Synchronously invoke \"notmuch\" with the given list of arguments.\r
207 =20\r
208 @@ -474,7 +527,7 @@ messages instead of running (notmuch-call-notmuch-proce=\r
209 ss \"tag\" ..)\r
210  directly, so that hooks specified in notmuch-before-tag-hook and\r
211  notmuch-after-tag-hook will be run."\r
212    (run-hooks 'notmuch-before-tag-hook)\r
213 -  (apply 'notmuch-call-notmuch-process\r
214 +  (apply 'notmuch-process-queue-command\r
215          (append (list "tag") tags (list "--" query)))\r
216    (run-hooks 'notmuch-after-tag-hook))\r
217 =20\r
218 --=20\r
219 1.7.8.2\r
220 \r
221 -----cut-here-----\r
222 \r
223 --=20\r
224 Aaron Ecay\r