dovecot-2.2: lib-storage: Added "oldestonly" search arg to stop ...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jan 14 22:12:29 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/14bf136959bc
changeset: 18147:14bf136959bc
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jan 15 00:10:56 2015 +0200
description:
lib-storage: Added "oldestonly" search arg to stop searching after the first non-match.
This parameter works only for doveadm search queries. It's not fully exact
currently, because if mailbox.search_next_update_seq() skips over
non-matching messages we don't stop if the next message matches. So this
parameter is mainly useful for optimization of commands like:

doveadm expunge -u user at domain mailbox inbox savedsince 30d oldestonly

Where the timestamps should be ascending all the time anyway and there's no
point in continuing to search for more mails after the first timestamp is
too high.

diffstat:

 src/lib-storage/index/index-search.c         |  12 +++++++++++-
 src/lib-storage/mail-search-build.c          |   3 +--
 src/lib-storage/mail-search-build.h          |   1 +
 src/lib-storage/mail-search-register-human.c |  10 +++++++++-
 src/lib-storage/mail-search.h                |   3 +++
 5 files changed, 25 insertions(+), 4 deletions(-)

diffs (97 lines):

diff -r e3640ccaa76d -r 14bf136959bc src/lib-storage/index/index-search.c
--- a/src/lib-storage/index/index-search.c	Sat Jan 10 04:32:42 2015 +0200
+++ b/src/lib-storage/index/index-search.c	Thu Jan 15 00:10:56 2015 +0200
@@ -1561,6 +1561,12 @@
 			break;
 		}
 
+		/* non-match */
+		if (_ctx->args->stop_on_nonmatch) {
+			ret = -1;
+			break;
+		}
+
 		cost2 = search_get_cost(mail->transaction);
 		ctx->cost += cost2 - cost1;
 		cost1 = cost2;
@@ -1685,10 +1691,14 @@
 		if (imail->data.search_results == NULL)
 			break;
 
-		/* searching wasn't finished yet */
+		/* prefetch running - searching wasn't finished yet */
 		if (search_finish_prefetch(ctx, imail))
 			break;
 		/* search finished as non-match */
+		if (ctx->mail_ctx.args->stop_on_nonmatch) {
+			ret = -1;
+			break;
+		}
 	}
 	return ret;
 }
diff -r e3640ccaa76d -r 14bf136959bc src/lib-storage/mail-search-build.c
--- a/src/lib-storage/mail-search-build.c	Sat Jan 10 04:32:42 2015 +0200
+++ b/src/lib-storage/mail-search-build.c	Thu Jan 15 00:10:56 2015 +0200
@@ -146,9 +146,8 @@
 	*args_r = NULL;
 	*error_r = NULL;
 
-	args = mail_search_build_init();
-
 	memset(&ctx, 0, sizeof(ctx));
+	ctx.args = args = mail_search_build_init();
 	ctx.pool = args->pool;
 	ctx.reg = reg;
 	ctx.parser = parser;
diff -r e3640ccaa76d -r 14bf136959bc src/lib-storage/mail-search-build.h
--- a/src/lib-storage/mail-search-build.h	Sat Jan 10 04:32:42 2015 +0200
+++ b/src/lib-storage/mail-search-build.h	Thu Jan 15 00:10:56 2015 +0200
@@ -8,6 +8,7 @@
 
 struct mail_search_build_context {
 	pool_t pool;
+	struct mail_search_args *args;
 	struct mail_search_register *reg;
 	struct mail_search_parser *parser;
 	const char *charset;
diff -r e3640ccaa76d -r 14bf136959bc src/lib-storage/mail-search-register-human.c
--- a/src/lib-storage/mail-search-register-human.c	Sat Jan 10 04:32:42 2015 +0200
+++ b/src/lib-storage/mail-search-register-human.c	Thu Jan 15 00:10:56 2015 +0200
@@ -159,6 +159,13 @@
 	return mail_search_build_str(ctx, SEARCH_MAILBOX_GUID);
 }
 
+static struct mail_search_arg *
+human_search_oldestonly(struct mail_search_build_context *ctx)
+{
+	ctx->args->stop_on_nonmatch = TRUE;
+	return mail_search_build_new(ctx, SEARCH_ALL);
+}
+
 static const struct mail_search_register_arg human_register_args[] = {
 	{ "OR", human_search_or },
 
@@ -183,7 +190,8 @@
 	/* Other Dovecot extensions: */
 	{ "GUID", human_search_guid },
 	{ "MAILBOX", human_search_mailbox },
-	{ "MAILBOX-GUID", human_search_mailbox_guid }
+	{ "MAILBOX-GUID", human_search_mailbox_guid },
+	{ "OLDESTONLY", human_search_oldestonly }
 };
 
 static struct mail_search_register *
diff -r e3640ccaa76d -r 14bf136959bc src/lib-storage/mail-search.h
--- a/src/lib-storage/mail-search.h	Sat Jan 10 04:32:42 2015 +0200
+++ b/src/lib-storage/mail-search.h	Thu Jan 15 00:10:56 2015 +0200
@@ -109,6 +109,9 @@
 
 	unsigned int simplified:1;
 	unsigned int have_inthreads:1;
+	/* Stop mail_search_next() when finding a non-matching mail.
+	   (Could be useful when wanting to find only the oldest mails.) */
+	unsigned int stop_on_nonmatch:1;
 };
 
 #define ARG_SET_RESULT(arg, res) \


More information about the dovecot-cvs mailing list