dovecot-1.2: fts: Cache "last indexed uid" lookups as long as ne...

dovecot at dovecot.org dovecot at dovecot.org
Sun Nov 30 01:27:26 EET 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/1e8f718884c4
changeset: 8496:1e8f718884c4
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Nov 29 22:52:54 2008 +0200
description:
fts: Cache "last indexed uid" lookups as long as new messages aren't added to mailbox.

diffstat:

2 files changed, 31 insertions(+), 2 deletions(-)
src/plugins/fts/fts-storage.c |   31 +++++++++++++++++++++++++++++--
src/plugins/fts/fts-storage.h |    2 ++

diffs (67 lines):

diff -r ffb37c392166 -r 1e8f718884c4 src/plugins/fts/fts-storage.c
--- a/src/plugins/fts/fts-storage.c	Sat Nov 29 22:39:44 2008 +0200
+++ b/src/plugins/fts/fts-storage.c	Sat Nov 29 22:52:54 2008 +0200
@@ -380,15 +380,35 @@ static int fts_build_init_virtual(struct
 
 static int fts_build_init(struct fts_search_context *fctx)
 {
+	struct mailbox_status status;
+	int ret;
+
+	mailbox_get_status(fctx->t->box, STATUS_MESSAGES | STATUS_UIDNEXT,
+			   &status);
+	if (status.messages == fctx->fbox->last_messages_count &&
+	    status.uidnext == fctx->fbox->last_uidnext) {
+		/* no new messages since last check */
+		return 0;
+	}
+
 	if (fctx->fbox->virtual)
-		return fts_build_init_virtual(fctx);
-	return fts_build_init_trans(fctx, fctx->t);
+		ret = fts_build_init_virtual(fctx);
+	else
+		ret = fts_build_init_trans(fctx, fctx->t);
+	if (ret == 0 && fctx->build_ctx == NULL) {
+		/* index was up-to-date */
+		fctx->fbox->last_messages_count = status.messages;
+		fctx->fbox->last_uidnext = status.uidnext;
+	}
+	return ret;
 }
 
 static int fts_build_deinit(struct fts_storage_build_context **_ctx)
 {
 	struct fts_storage_build_context *ctx = *_ctx;
 	struct mailbox *box = ctx->mail->transaction->box;
+	struct fts_mailbox *fbox = FTS_CONTEXT(box);
+	struct mailbox_status status;
 	int ret = 0;
 
 	*_ctx = NULL;
@@ -399,6 +419,13 @@ static int fts_build_deinit(struct fts_s
 
 	if (fts_backend_build_deinit(&ctx->build) < 0)
 		ret = -1;
+
+	if (ret == 0) {
+		mailbox_get_status(box, STATUS_MESSAGES | STATUS_UIDNEXT,
+				   &status);
+		fbox->last_messages_count = status.messages;
+		fbox->last_uidnext = status.uidnext;
+	}
 
 	if (ioloop_time - ctx->search_start_time.tv_sec >=
 	    FTS_BUILD_NOTIFY_INTERVAL_SECS) {
diff -r ffb37c392166 -r 1e8f718884c4 src/plugins/fts/fts-storage.h
--- a/src/plugins/fts/fts-storage.h	Sat Nov 29 22:39:44 2008 +0200
+++ b/src/plugins/fts/fts-storage.h	Sat Nov 29 22:52:54 2008 +0200
@@ -5,6 +5,8 @@ struct fts_mailbox {
 	union mailbox_module_context module_ctx;
 	struct fts_backend *backend_substr;
 	struct fts_backend *backend_fast;
+
+	unsigned int last_messages_count, last_uidnext;
 
 	const char *env;
 	unsigned int virtual:1;


More information about the dovecot-cvs mailing list