dovecot-1.1: Nonblocking search should handle more messages when...

dovecot at dovecot.org dovecot at dovecot.org
Wed Apr 29 00:00:06 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.1/rev/8e597c226093
changeset: 8253:8e597c226093
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Apr 28 17:00:01 2009 -0400
description:
Nonblocking search should handle more messages when body isn't being searched.
This should improve SEARCH speeds on larger mailboxes.

diffstat:

1 file changed, 12 insertions(+), 3 deletions(-)
src/lib-storage/index/index-search.c |   15 ++++++++++++---

diffs (60 lines):

diff -r 685c1be82282 -r 8e597c226093 src/lib-storage/index/index-search.c
--- a/src/lib-storage/index/index-search.c	Thu Apr 23 12:01:40 2009 -0400
+++ b/src/lib-storage/index/index-search.c	Tue Apr 28 17:00:01 2009 -0400
@@ -21,7 +21,8 @@
 #define TXT_UNKNOWN_CHARSET "[BADCHARSET] Unknown charset"
 #define TXT_INVALID_SEARCH_KEY "Invalid search key"
 
-#define SEARCH_NONBLOCK_COUNT 20
+#define SEARCH_BODY_COST 20
+#define SEARCH_NONBLOCK_MAX_COST 1000
 #define SEARCH_NOTIFY_INTERVAL_SECS 10
 
 struct index_search_context {
@@ -42,6 +43,7 @@ struct index_search_context {
 	unsigned int sorted:1;
 	unsigned int have_seqsets:1;
 	unsigned int have_flags_or_keywords:1;
+	unsigned int searched_body:1;
 };
 
 struct search_header_context {
@@ -593,6 +595,7 @@ static bool search_arg_match_text(struct
 	if (have_body) {
 		struct search_body_context body_ctx;
 
+		ctx->searched_body = TRUE;
 		memset(&body_ctx, 0, sizeof(body_ctx));
 		body_ctx.index_ctx = ctx;
 		body_ctx.input = input;
@@ -1015,7 +1018,7 @@ int index_storage_search_next_nonblock(s
 {
         struct index_search_context *ctx = (struct index_search_context *)_ctx;
 	struct mailbox *box = _ctx->transaction->box;
-	unsigned int count = 0;
+	unsigned int cost = 0;
 	int ret;
 
 	*tryagain_r = FALSE;
@@ -1038,6 +1041,7 @@ int index_storage_search_next_nonblock(s
 	while ((ret = box->v.search_next_update_seq(_ctx)) > 0) {
 		mail_set_seq(mail, _ctx->seq);
 
+		ctx->searched_body = FALSE;
 		T_BEGIN {
 			ret = search_match_next(ctx) ? 1 : 0;
 		} T_END;
@@ -1053,7 +1057,12 @@ int index_storage_search_next_nonblock(s
 			index_sort_list_add(ctx->mail_ctx.sort_program, mail);
 		}
 
-		if (++count == SEARCH_NONBLOCK_COUNT) {
+		if (ctx->searched_body)
+			cost += SEARCH_BODY_COST;
+		else
+			cost++;
+
+		if (cost >= SEARCH_NONBLOCK_MAX_COST) {
 			*tryagain_r = TRUE;
 			return 0;
 		}


More information about the dovecot-cvs mailing list