Gnus development mailing list
 help / color / mirror / Atom feed
From: Julien Danjou <julien@danjou.info>
To: Michael Welsh Duggan <mwd@cert.org>
Cc: ding@gnus.org,  Michael Welsh Duggan <md5i@md5i.com>
Subject: Re: searching by Message-ID after copy/move; speeding things up
Date: Fri, 15 Jun 2012 16:17:19 +0200	[thread overview]
Message-ID: <87k3z8ek28.fsf@zelenka.enovance.com> (raw)
In-Reply-To: <tntipetwt4k.fsf@waterbuck.yellow.cert.org> (Michael Welsh Duggan's message of "Thu, 14 Jun 2012 16:11:55 -0400")


[-- Attachment #1.1: Type: text/plain, Size: 393 bytes --]

On Thu, Jun 14 2012, Michael Welsh Duggan wrote:

> Honestly, I'd just do a limited search.  You're already doing an
> EXAMINE, so you just need to parse the results to get the EXISTS count.
> Then a "UID SEARCH N:* HEADER Message-ID ..."  where N is the exist
> count minus a small constant.
>
> If the limited search fails, just re-call the function with recent set
> to nil.

Another try.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Add-recent-argument-to-nnimap-find-article-by-messag.patch --]
[-- Type: text/x-diff, Size: 3325 bytes --]

From f14188ce0cdfba2bfe27bcf8e88b3945841a3a4b Mon Sep 17 00:00:00 2001
From: Julien Danjou <julien@danjou.info>
Date: Thu, 14 Jun 2012 10:09:04 +0200
Subject: [PATCH] Add recent argument to nnimap-find-article-by-message-id

Signed-off-by: Julien Danjou <julien@danjou.info>
---
 lisp/nnimap.el |   40 ++++++++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/lisp/nnimap.el b/lisp/nnimap.el
index 1db8640..e50fc0e 100644
--- a/lisp/nnimap.el
+++ b/lisp/nnimap.el
@@ -123,6 +123,10 @@ will fetch all parts that have types that match that string.  A
 likely value would be \"text/\" to automatically fetch all
 textual parts.")
 
+(defcustom nnimap-request-move-articles-find-limit nil
+  "Limit the number of articles to look for after moving an article."
+  :type 'integer)
+
 (defvar nnimap-process nil)
 
 (defvar nnimap-status-string "")
@@ -867,7 +871,8 @@ textual parts.")
 		(cons internal-move-group
 		      (or (nnimap-find-uid-response "COPYUID" (cadr result))
 			  (nnimap-find-article-by-message-id
-			   internal-move-group server message-id)))))
+			   internal-move-group server message-id
+                           nnimap-request-move-articles-find-limit)))))
 	  ;; Move the article to a different method.
 	  (let ((result (eval accept-form)))
 	    (when result
@@ -969,21 +974,28 @@ textual parts.")
 			       (cdr (assoc "SEARCH" (cdr result))))))))))
 
 
-(defun nnimap-find-article-by-message-id (group server message-id)
-  "Search for message with MESSAGE-ID in GROUP from SERVER."
+(defun nnimap-find-article-by-message-id (group server message-id &optional limit)
+  "Search for message with MESSAGE-ID in GROUP from SERVER.
+If LIMIT, first try to limit the search to the N last articles."
   (with-current-buffer (nnimap-buffer)
     (erase-buffer)
-    (nnimap-change-group group server nil t)
-    (let ((sequence
-	   (nnimap-send-command "UID SEARCH HEADER Message-Id %S" message-id))
-	  article result)
-      (setq result (nnimap-wait-for-response sequence))
-      (when (and result
-		 (car (setq result (nnimap-parse-response))))
-	;; Select the last instance of the message in the group.
-	(and (setq article
-		   (car (last (cdr (assoc "SEARCH" (cdr result))))))
-	     (string-to-number article))))))
+    (let* ((number-of-article
+           (catch 'found
+             (dolist (result (cdr (nnimap-change-group group server nil t)))
+               (when (equal "EXISTS" (cadr result))
+                 (throw 'found (car result))))))
+           (sequence
+            (nnimap-send-command "UID SEARCH%s HEADER Message-Id %S"
+                                 (if limit
+                                     (format " %s:*" (- number-of-article limit))
+                                   "")
+                                 message-id)))
+      (when (nnimap-wait-for-response sequence)
+        (let ((article (car (last (cdr (assoc "SEARCH" (nnimap-parse-response)))))))
+          (if article
+              (string-to-number article)
+            (when limit
+              (nnimap-find-article-by-message-id group server message-id))))))))
 
 (defun nnimap-delete-article (articles)
   (with-current-buffer (nnimap-buffer)
-- 
1.7.10


[-- Attachment #1.3: Type: text/plain, Size: 243 bytes --]


While I was at it I modified a bunch of code in nnimap that I pushed
into master. I hope I didn't break anything, but I think it's a bit
cleaner that way. If it break something we can beat me and revert
anyway.

-- 
           Julien

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

  reply	other threads:[~2012-06-15 14:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-14  4:42 Michael Welsh Duggan
2012-06-14  8:10 ` Julien Danjou
2012-06-14 19:51   ` Michael Welsh Duggan
2012-06-14 19:59     ` Julien Danjou
2012-06-14 20:11       ` Michael Welsh Duggan
2012-06-15 14:17         ` Julien Danjou [this message]
2012-06-15 15:11           ` Michael Welsh Duggan
2012-06-19  8:53             ` Julien Danjou
2012-06-19 15:33               ` Michael Welsh Duggan
2012-06-25 11:23                 ` Julien Danjou
2012-06-25 14:00                   ` Michael Welsh Duggan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k3z8ek28.fsf@zelenka.enovance.com \
    --to=julien@danjou.info \
    --cc=ding@gnus.org \
    --cc=md5i@md5i.com \
    --cc=mwd@cert.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).