dovecot-1.2: Give more correct "* OK searched n%" notifications ...

dovecot at dovecot.org dovecot at dovecot.org
Sun Nov 30 16:29:21 EET 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/f323bf2465bd
changeset: 8507:f323bf2465bd
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Nov 30 15:57:41 2008 +0200
description:
Give more correct "* OK searched n%" notifications with fts and virtual mailboxes.

diffstat:

4 files changed, 59 insertions(+), 18 deletions(-)
src/lib-storage/index/index-search.c   |   15 +++++---
src/lib-storage/mail-storage-private.h |    2 +
src/plugins/fts/fts-storage.c          |   55 ++++++++++++++++++++++++--------
src/plugins/virtual/virtual-search.c   |    5 ++

diffs (224 lines):

diff -r 52f95ea3932b -r f323bf2465bd src/lib-storage/index/index-search.c
--- a/src/lib-storage/index/index-search.c	Sun Nov 30 15:49:42 2008 +0200
+++ b/src/lib-storage/index/index-search.c	Sun Nov 30 15:57:41 2008 +0200
@@ -972,6 +972,7 @@ index_storage_search_init(struct mailbox
 	struct index_transaction_context *t =
 		(struct index_transaction_context *)_t;
 	struct index_search_context *ctx;
+	const struct mail_index_header *hdr;
 
 	ctx = i_new(struct index_search_context, 1);
 	ctx->mail_ctx.transaction = _t;
@@ -979,6 +980,9 @@ index_storage_search_init(struct mailbox
 	ctx->view = t->trans_view;
 	ctx->mail_ctx.args = args;
 	ctx->mail_ctx.sort_program = index_sort_program_init(_t, sort_program);
+
+	hdr = mail_index_get_header(t->ibox->view);
+	ctx->mail_ctx.progress_max = hdr->messages_count;
 
 	i_array_init(&ctx->mail_ctx.results, 5);
 	array_create(&ctx->mail_ctx.module_contexts, default_pool,
@@ -1063,7 +1067,6 @@ static void index_storage_search_notify(
 static void index_storage_search_notify(struct mailbox *box,
 					struct index_search_context *ctx)
 {
-	const struct mail_index_header *hdr;
 	float percentage;
 	unsigned int msecs, secs;
 
@@ -1072,9 +1075,8 @@ static void index_storage_search_notify(
 		   already spent some time indexing the mailbox */
 		ctx->search_start_time = ioloop_timeval;
 	} else if (box->storage->callbacks->notify_ok != NULL) {
-		hdr = mail_index_get_header(ctx->ibox->view);
-
-		percentage = ctx->mail->seq * 100.0 / hdr->messages_count;
+		percentage = ctx->mail_ctx.progress_cur * 100.0 /
+			ctx->mail_ctx.progress_max;
 		msecs = (ioloop_timeval.tv_sec -
 			 ctx->search_start_time.tv_sec) * 1000 +
 			(ioloop_timeval.tv_usec -
@@ -1246,8 +1248,10 @@ bool index_storage_search_next_update_se
 	}
 
 	if (!ctx->have_seqsets && !ctx->have_index_args &&
-	    _ctx->update_result == NULL)
+	    _ctx->update_result == NULL) {
+		ctx->mail_ctx.progress_cur = _ctx->seq;
 		return _ctx->seq <= ctx->seq2;
+	}
 
 	ret = 0;
 	while (_ctx->seq <= ctx->seq2) {
@@ -1283,5 +1287,6 @@ bool index_storage_search_next_update_se
 			search_set_static_matches(_ctx->args->args);
 		}
 	}
+	ctx->mail_ctx.progress_cur = _ctx->seq;
 	return ret != 0;
 }
diff -r 52f95ea3932b -r f323bf2465bd src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Sun Nov 30 15:49:42 2008 +0200
+++ b/src/lib-storage/mail-storage-private.h	Sun Nov 30 15:57:41 2008 +0200
@@ -324,6 +324,8 @@ struct mail_search_context {
 	ARRAY_DEFINE(results, struct mail_search_result *);
 
 	uint32_t seq;
+	uint32_t progress_cur, progress_max;
+
 	ARRAY_DEFINE(module_contexts, union mail_search_module_context *);
 
 	unsigned int seen_lost_data:1;
diff -r 52f95ea3932b -r f323bf2465bd src/plugins/fts/fts-storage.c
--- a/src/plugins/fts/fts-storage.c	Sun Nov 30 15:49:42 2008 +0200
+++ b/src/plugins/fts/fts-storage.c	Sun Nov 30 15:57:41 2008 +0200
@@ -519,7 +519,20 @@ static int fts_build_more(struct fts_sto
 	return 1;
 }
 
-static bool fts_try_build_init(struct fts_search_context *fctx)
+static void fts_search_init_lookup(struct mail_search_context *ctx,
+				   struct fts_search_context *fctx)
+{
+	fts_search_lookup(fctx);
+
+	if (fctx->seqs_set &&
+	    strcmp(ctx->transaction->box->storage->name, "virtual") != 0) {
+		ctx->progress_max = array_count(&fctx->definite_seqs) +
+			array_count(&fctx->maybe_seqs);
+	}
+}
+
+static bool fts_try_build_init(struct mail_search_context *ctx,
+			       struct fts_search_context *fctx)
 {
 	if (fctx->build_backend == NULL) {
 		fctx->build_initialized = TRUE;
@@ -539,7 +552,7 @@ static bool fts_try_build_init(struct ft
 
 	if (fctx->build_ctx == NULL) {
 		/* the index was up to date */
-		fts_search_lookup(fctx);
+		fts_search_init_lookup(ctx, fctx);
 	}
 	return TRUE;
 }
@@ -569,7 +582,7 @@ fts_mailbox_search_init(struct mailbox_t
 	ft->score_map = &fctx->score_map;
 
 	fts_search_analyze(fctx);
-	(void)fts_try_build_init(fctx);
+	(void)fts_try_build_init(ctx, fctx);
 	return ctx;
 }
 
@@ -583,7 +596,7 @@ static int fts_mailbox_search_next_nonbl
 	if (!fctx->build_initialized) {
 		/* we're still waiting for this process (but another command)
 		   to finish building the indexes */
-		if (!fts_try_build_init(fctx)) {
+		if (!fts_try_build_init(ctx, fctx)) {
 			*tryagain_r = TRUE;
 			return 0;
 		}
@@ -603,7 +616,7 @@ static int fts_mailbox_search_next_nonbl
 		if (ret > 0) {
 			if (fts_build_init_virtual_next(fctx) == 0) {
 				/* all finished */
-				fts_search_lookup(fctx);
+				fts_search_init_lookup(ctx, fctx);
 			}
 		}
 	}
@@ -622,6 +635,10 @@ fts_mailbox_search_args_definite_set(str
 		switch (arg->type) {
 		case SEARCH_TEXT:
 		case SEARCH_BODY:
+			if (fctx->fbox->backend_substr == NULL) {
+				/* we're marking only fast args */
+				break;
+			}
 		case SEARCH_BODY_FAST:
 		case SEARCH_TEXT_FAST:
 			arg->result = 1;
@@ -630,6 +647,21 @@ fts_mailbox_search_args_definite_set(str
 			break;
 		}
 	}
+}
+
+static bool search_nonindexed(struct mail_search_context *ctx)
+{
+	struct fts_search_context *fctx = FTS_CONTEXT(ctx);
+	struct fts_mailbox *fbox = FTS_CONTEXT(ctx->transaction->box);
+	struct mailbox_status status;
+
+	mailbox_get_status(ctx->transaction->box, STATUS_MESSAGES, &status);
+
+	fctx->seqs_set = FALSE;
+	ctx->seq = fctx->first_nonindexed_seq - 1;
+	ctx->progress_cur = ctx->seq;
+	ctx->progress_max = status.messages;
+	return fbox->module_ctx.super.search_next_update_seq(ctx);
 }
 
 static bool fts_mailbox_search_next_update_seq(struct mail_search_context *ctx)
@@ -665,9 +697,7 @@ static bool fts_mailbox_search_next_upda
 				/* look for the non-indexed mails */
 				if (fctx->first_nonindexed_seq == (uint32_t)-1)
 					return FALSE;
-				fctx->seqs_set = FALSE;
-				ctx->seq = fctx->first_nonindexed_seq - 1;
-				return fts_mailbox_search_next_update_seq(ctx);
+				return search_nonindexed(ctx);
 			}
 			use_maybe = TRUE;
 		} else if (fctx->maybe_idx == maybe_count) {
@@ -714,11 +744,10 @@ static bool fts_mailbox_search_next_upda
 		   to avoid duplicates or jumping around, ignore the rest of
 		   the search results and just go through the messages in
 		   order. */
-		fctx->seqs_set = FALSE;
-		ctx->seq = fctx->first_nonindexed_seq - 1;
-		return fts_mailbox_search_next_update_seq(ctx);
-	}
-
+		return search_nonindexed(ctx);
+	}
+
+	ctx->progress_cur = fctx->definite_idx + fctx->maybe_idx;
 	return ret;
 }
 
diff -r 52f95ea3932b -r f323bf2465bd src/plugins/virtual/virtual-search.c
--- a/src/plugins/virtual/virtual-search.c	Sun Nov 30 15:49:42 2008 +0200
+++ b/src/plugins/virtual/virtual-search.c	Sun Nov 30 15:57:41 2008 +0200
@@ -99,6 +99,8 @@ static int virtual_search_get_records(st
 	}
 	srecs = array_get_modifiable(&vctx->records, &count);
 	qsort(srecs, count, sizeof(*srecs), virtual_search_record_cmp);
+
+	ctx->progress_max = count;
 	return ret;
 }
 
@@ -191,15 +193,18 @@ bool virtual_search_next_update_seq(stru
 
 	recs = array_get(&vctx->records, &count);
 	if (vctx->next_record_idx < count) {
+		/* go through potential results first */
 		ctx->seq = recs[vctx->next_record_idx++].virtual_seq - 1;
 		if (!index_storage_search_next_update_seq(ctx))
 			i_unreached();
+		ctx->progress_cur = vctx->next_record_idx;
 		return TRUE;
 	}
 
 	if (ctx->sort_program != NULL &&
 	    seq_range_array_iter_nth(&vctx->result_iter,
 				     vctx->next_result_n, &ctx->seq)) {
+		/* this is known to match fully */
 		search_args_set_full_match(ctx->args->args);
 		vctx->next_result_n++;
 		return TRUE;


More information about the dovecot-cvs mailing list