dovecot: Return in OK reply how long the SEARCH took.

dovecot at dovecot.org dovecot at dovecot.org
Fri Dec 7 00:46:35 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/0a93c4e07776
changeset: 6943:0a93c4e07776
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Dec 07 00:46:31 2007 +0200
description:
Return in OK reply how long the SEARCH took.

diffstat:

1 file changed, 19 insertions(+), 4 deletions(-)
src/imap/cmd-search.c |   23 +++++++++++++++++++----

diffs (62 lines):

diff -r 3af80c378959 -r 0a93c4e07776 src/imap/cmd-search.c
--- a/src/imap/cmd-search.c	Fri Dec 07 00:45:59 2007 +0200
+++ b/src/imap/cmd-search.c	Fri Dec 07 00:46:31 2007 +0200
@@ -16,6 +16,8 @@ struct imap_search_context {
 	struct timeout *to;
 	string_t *output_buf;
 
+	struct timeval start_time;
+
 	unsigned int output_sent:1;
 };
 
@@ -29,6 +31,7 @@ imap_search_init(struct client_command_c
 	ctx->trans = mailbox_transaction_begin(cmd->client->mailbox, 0);
 	ctx->search_ctx = mailbox_search_init(ctx->trans, charset, sargs, NULL);
 	ctx->mail = mail_alloc(ctx->trans, 0, NULL);
+	(void)gettimeofday(&ctx->start_time, NULL);
 
 	ctx->output_buf = str_new(default_pool, OUTBUF_SIZE);
 	str_append(ctx->output_buf, "* SEARCH");
@@ -63,6 +66,7 @@ static bool cmd_search_more(struct clien
 static bool cmd_search_more(struct client_command_context *cmd)
 {
 	struct imap_search_context *ctx = cmd->context;
+	struct timeval end_time;
 	bool tryagain;
 	int ret;
 
@@ -89,6 +93,15 @@ static bool cmd_search_more(struct clien
 	if (tryagain)
 		return FALSE;
 
+	if (gettimeofday(&end_time, NULL) < 0)
+		memset(&end_time, 0, sizeof(end_time));
+	end_time.tv_sec -= ctx->start_time.tv_sec;
+	end_time.tv_usec -= ctx->start_time.tv_usec;
+	if (end_time.tv_usec < 0) {
+		end_time.tv_sec++;
+		end_time.tv_usec += 1000000;
+	}
+
 	if (imap_search_deinit(cmd, ctx) < 0)
 		ret = -1;
 
@@ -96,11 +109,13 @@ static bool cmd_search_more(struct clien
 		client_send_storage_error(cmd,
 			mailbox_get_storage(cmd->client->mailbox));
 		return TRUE;
-	} else {
-		return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST |
-				(cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES),
-				0, "OK Search completed.");
 	}
+
+	return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST |
+			(cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES), 0,
+			t_strdup_printf("OK Search completed (%d.%03d secs).",
+					(int)end_time.tv_sec,
+					(int)(end_time.tv_usec/1000)));
 }
 
 static void cmd_search_more_callback(struct client_command_context *cmd)


More information about the dovecot-cvs mailing list