changeset 13265:2d4175c9ff52

fts-lucene: Don't add messages to expunge log that aren't even in the index.
author Timo Sirainen <tss@iki.fi>
date Tue, 16 Aug 2011 22:26:12 +0300
parents 86d752132290
children ee151b7e0d5a
files src/plugins/fts-lucene/fts-backend-lucene.c
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/fts-lucene/fts-backend-lucene.c	Tue Aug 16 22:23:48 2011 +0300
+++ b/src/plugins/fts-lucene/fts-backend-lucene.c	Tue Aug 16 22:26:12 2011 +0300
@@ -37,6 +37,7 @@
 
 	struct mailbox *box;
 	uint32_t last_uid;
+	uint32_t last_indexed_uid;
 	char *first_box_vname;
 
 	uint32_t uid;
@@ -46,6 +47,7 @@
 	struct fts_expunge_log_append_ctx *expunge_ctx;
 
 	bool lucene_opened;
+	bool last_indexed_uid_set;
 };
 
 static int fts_backend_lucene_mkdir(struct lucene_fts_backend *backend)
@@ -276,6 +278,7 @@
 	if (ctx->first_box_vname == NULL)
 		ctx->first_box_vname = i_strdup(box->vname);
 	ctx->box = box;
+	ctx->last_indexed_uid_set = FALSE;
 }
 
 static void
@@ -287,6 +290,21 @@
 	struct lucene_fts_backend *backend =
 		(struct lucene_fts_backend *)_ctx->backend;
 
+	if (!ctx->last_indexed_uid_set) {
+		if (!fts_index_get_last_uid(ctx->box, &ctx->last_indexed_uid))
+			ctx->last_indexed_uid = 0;
+		ctx->last_indexed_uid_set = TRUE;
+	}
+	if (ctx->last_indexed_uid == 0 ||
+	    uid > ctx->last_indexed_uid + 100) {
+		/* don't waste time adding expunge to log for a message that
+		   isn't even indexed. this check is racy, because indexer may
+		   just be in the middle of indexing this message. we'll
+		   attempt to avoid that by skipping the expunging only if
+		   indexing hasn't been done for a while (100 msgs). */
+		return;
+	}
+
 	if (ctx->expunge_ctx == NULL) {
 		ctx->expunge_ctx =
 			fts_expunge_log_append_begin(backend->expunge_log);