Mercurial > dovecot > core-2.2
changeset 13369:338ba56340c0
fts-solr: Don't send delete to Solr if we're quite sure it doesn't exist.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 02 Sep 2011 07:11:16 +0300 |
parents | 1c2d8da38a06 |
children | d2b27eae9221 |
files | src/plugins/fts-solr/fts-backend-solr.c |
diffstat | 1 files changed, 32 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/fts-solr/fts-backend-solr.c Thu Sep 01 17:52:51 2011 +0300 +++ b/src/plugins/fts-solr/fts-backend-solr.c Fri Sep 02 07:11:16 2011 +0300 @@ -32,9 +32,13 @@ uint32_t prev_uid; string_t *cmd, *hdr, *hdr_fields; - bool headers_open; - bool cur_header_index; - bool documents_added; + uint32_t last_indexed_uid; + + unsigned int last_indexed_uid_set:1; + unsigned int headers_open:1; + unsigned int cur_header_index:1; + unsigned int documents_added:1; + unsigned int expunges:1; }; static struct solr_connection *solr_conn = NULL; @@ -294,13 +298,15 @@ if (fts_backed_solr_build_commit(ctx) < 0) ret = -1; - /* commit and wait until the documents we just indexed are - visible to the following search */ - str = t_strdup_printf("<commit waitFlush=\"false\" " - "waitSearcher=\"%s\"/>", - ctx->documents_added ? "true" : "false"); - if (solr_connection_post(solr_conn, str) < 0) - ret = -1; + if (ctx->documents_added || ctx->expunges) { + /* commit and wait until the documents we just indexed are + visible to the following search */ + str = t_strdup_printf("<commit waitFlush=\"false\" " + "waitSearcher=\"%s\"/>", + ctx->documents_added ? "true" : "false"); + if (solr_connection_post(solr_conn, str) < 0) + ret = -1; + } str_free(&ctx->cmd); str_free(&ctx->hdr); @@ -340,6 +346,22 @@ { struct solr_fts_backend_update_context *ctx = (struct solr_fts_backend_update_context *)_ctx; + struct fts_index_header hdr; + + if (!ctx->last_indexed_uid_set) { + if (!fts_index_get_header(ctx->cur_box, &hdr)) + ctx->last_indexed_uid = 0; + else + ctx->last_indexed_uid = hdr.last_indexed_uid; + ctx->last_indexed_uid_set = TRUE; + } + if (ctx->last_indexed_uid == 0 || + uid > ctx->last_indexed_uid + 100) { + /* don't waste time asking Solr to expunge a message that is + highly unlikely to be indexed at this time. */ + return; + } + ctx->expunges = TRUE; T_BEGIN { string_t *cmd;