]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Give more correct "* OK searched n%" notifications with fts and virtual mailboxes.
authorTimo Sirainen <tss@iki.fi>
Sun, 30 Nov 2008 13:57:41 +0000 (15:57 +0200)
committerTimo Sirainen <tss@iki.fi>
Sun, 30 Nov 2008 13:57:41 +0000 (15:57 +0200)
--HG--
branch : HEAD

src/lib-storage/index/index-search.c
src/lib-storage/mail-storage-private.h
src/plugins/fts/fts-storage.c
src/plugins/virtual/virtual-search.c

index de1c360e70516528d2e7b9f2b215c045cf9f6eed..3dc342f06d8307025cf8d5fa4b8a760cb32a7f73 100644 (file)
@@ -972,6 +972,7 @@ index_storage_search_init(struct mailbox_transaction_context *_t,
        struct index_transaction_context *t =
                (struct index_transaction_context *)_t;
        struct index_search_context *ctx;
+       const struct mail_index_header *hdr;
 
        ctx = i_new(struct index_search_context, 1);
        ctx->mail_ctx.transaction = _t;
@@ -980,6 +981,9 @@ index_storage_search_init(struct mailbox_transaction_context *_t,
        ctx->mail_ctx.args = args;
        ctx->mail_ctx.sort_program = index_sort_program_init(_t, sort_program);
 
+       hdr = mail_index_get_header(t->ibox->view);
+       ctx->mail_ctx.progress_max = hdr->messages_count;
+
        i_array_init(&ctx->mail_ctx.results, 5);
        array_create(&ctx->mail_ctx.module_contexts, default_pool,
                     sizeof(void *), 5);
@@ -1063,7 +1067,6 @@ static bool search_match_next(struct index_search_context *ctx)
 static void index_storage_search_notify(struct mailbox *box,
                                        struct index_search_context *ctx)
 {
-       const struct mail_index_header *hdr;
        float percentage;
        unsigned int msecs, secs;
 
@@ -1072,9 +1075,8 @@ static void index_storage_search_notify(struct mailbox *box,
                   already spent some time indexing the mailbox */
                ctx->search_start_time = ioloop_timeval;
        } else if (box->storage->callbacks->notify_ok != NULL) {
-               hdr = mail_index_get_header(ctx->ibox->view);
-
-               percentage = ctx->mail->seq * 100.0 / hdr->messages_count;
+               percentage = ctx->mail_ctx.progress_cur * 100.0 /
+                       ctx->mail_ctx.progress_max;
                msecs = (ioloop_timeval.tv_sec -
                         ctx->search_start_time.tv_sec) * 1000 +
                        (ioloop_timeval.tv_usec -
@@ -1246,8 +1248,10 @@ bool index_storage_search_next_update_seq(struct mail_search_context *_ctx)
        }
 
        if (!ctx->have_seqsets && !ctx->have_index_args &&
-           _ctx->update_result == NULL)
+           _ctx->update_result == NULL) {
+               ctx->mail_ctx.progress_cur = _ctx->seq;
                return _ctx->seq <= ctx->seq2;
+       }
 
        ret = 0;
        while (_ctx->seq <= ctx->seq2) {
@@ -1283,5 +1287,6 @@ bool index_storage_search_next_update_seq(struct mail_search_context *_ctx)
                        search_set_static_matches(_ctx->args->args);
                }
        }
+       ctx->mail_ctx.progress_cur = _ctx->seq;
        return ret != 0;
 }
index 4af0f9024fcdb1bc4190027dfd4a49329a8f4d8b..b82e56e12ac1336a183a1f6e24decf601e97f1bb 100644 (file)
@@ -324,6 +324,8 @@ struct mail_search_context {
        ARRAY_DEFINE(results, struct mail_search_result *);
 
        uint32_t seq;
+       uint32_t progress_cur, progress_max;
+
        ARRAY_DEFINE(module_contexts, union mail_search_module_context *);
 
        unsigned int seen_lost_data:1;
index ee703a2cf6c83cb9e3806c7b31abddf86c5ef946..cde9e091e9b2a25bc48ed439163e472db6aa8e96 100644 (file)
@@ -519,7 +519,20 @@ static int fts_build_more(struct fts_storage_build_context *ctx)
        return 1;
 }
 
-static bool fts_try_build_init(struct fts_search_context *fctx)
+static void fts_search_init_lookup(struct mail_search_context *ctx,
+                                  struct fts_search_context *fctx)
+{
+       fts_search_lookup(fctx);
+
+       if (fctx->seqs_set &&
+           strcmp(ctx->transaction->box->storage->name, "virtual") != 0) {
+               ctx->progress_max = array_count(&fctx->definite_seqs) +
+                       array_count(&fctx->maybe_seqs);
+       }
+}
+
+static bool fts_try_build_init(struct mail_search_context *ctx,
+                              struct fts_search_context *fctx)
 {
        if (fctx->build_backend == NULL) {
                fctx->build_initialized = TRUE;
@@ -539,7 +552,7 @@ static bool fts_try_build_init(struct fts_search_context *fctx)
 
        if (fctx->build_ctx == NULL) {
                /* the index was up to date */
-               fts_search_lookup(fctx);
+               fts_search_init_lookup(ctx, fctx);
        }
        return TRUE;
 }
@@ -569,7 +582,7 @@ fts_mailbox_search_init(struct mailbox_transaction_context *t,
        ft->score_map = &fctx->score_map;
 
        fts_search_analyze(fctx);
-       (void)fts_try_build_init(fctx);
+       (void)fts_try_build_init(ctx, fctx);
        return ctx;
 }
 
@@ -583,7 +596,7 @@ static int fts_mailbox_search_next_nonblock(struct mail_search_context *ctx,
        if (!fctx->build_initialized) {
                /* we're still waiting for this process (but another command)
                   to finish building the indexes */
-               if (!fts_try_build_init(fctx)) {
+               if (!fts_try_build_init(ctx, fctx)) {
                        *tryagain_r = TRUE;
                        return 0;
                }
@@ -603,7 +616,7 @@ static int fts_mailbox_search_next_nonblock(struct mail_search_context *ctx,
                if (ret > 0) {
                        if (fts_build_init_virtual_next(fctx) == 0) {
                                /* all finished */
-                               fts_search_lookup(fctx);
+                               fts_search_init_lookup(ctx, fctx);
                        }
                }
        }
@@ -622,6 +635,10 @@ fts_mailbox_search_args_definite_set(struct fts_search_context *fctx)
                switch (arg->type) {
                case SEARCH_TEXT:
                case SEARCH_BODY:
+                       if (fctx->fbox->backend_substr == NULL) {
+                               /* we're marking only fast args */
+                               break;
+                       }
                case SEARCH_BODY_FAST:
                case SEARCH_TEXT_FAST:
                        arg->result = 1;
@@ -632,6 +649,21 @@ fts_mailbox_search_args_definite_set(struct fts_search_context *fctx)
        }
 }
 
+static bool search_nonindexed(struct mail_search_context *ctx)
+{
+       struct fts_search_context *fctx = FTS_CONTEXT(ctx);
+       struct fts_mailbox *fbox = FTS_CONTEXT(ctx->transaction->box);
+       struct mailbox_status status;
+
+       mailbox_get_status(ctx->transaction->box, STATUS_MESSAGES, &status);
+
+       fctx->seqs_set = FALSE;
+       ctx->seq = fctx->first_nonindexed_seq - 1;
+       ctx->progress_cur = ctx->seq;
+       ctx->progress_max = status.messages;
+       return fbox->module_ctx.super.search_next_update_seq(ctx);
+}
+
 static bool fts_mailbox_search_next_update_seq(struct mail_search_context *ctx)
 {
        struct fts_mailbox *fbox = FTS_CONTEXT(ctx->transaction->box);
@@ -665,9 +697,7 @@ static bool fts_mailbox_search_next_update_seq(struct mail_search_context *ctx)
                                /* look for the non-indexed mails */
                                if (fctx->first_nonindexed_seq == (uint32_t)-1)
                                        return FALSE;
-                               fctx->seqs_set = FALSE;
-                               ctx->seq = fctx->first_nonindexed_seq - 1;
-                               return fts_mailbox_search_next_update_seq(ctx);
+                               return search_nonindexed(ctx);
                        }
                        use_maybe = TRUE;
                } else if (fctx->maybe_idx == maybe_count) {
@@ -714,11 +744,10 @@ static bool fts_mailbox_search_next_update_seq(struct mail_search_context *ctx)
                   to avoid duplicates or jumping around, ignore the rest of
                   the search results and just go through the messages in
                   order. */
-               fctx->seqs_set = FALSE;
-               ctx->seq = fctx->first_nonindexed_seq - 1;
-               return fts_mailbox_search_next_update_seq(ctx);
+               return search_nonindexed(ctx);
        }
 
+       ctx->progress_cur = fctx->definite_idx + fctx->maybe_idx;
        return ret;
 }
 
index f45836708930a02fe376742c9078d2247bb3835f..a481c655df735343079a42d3d5c5ea053695e53d 100644 (file)
@@ -99,6 +99,8 @@ static int virtual_search_get_records(struct mail_search_context *ctx,
        }
        srecs = array_get_modifiable(&vctx->records, &count);
        qsort(srecs, count, sizeof(*srecs), virtual_search_record_cmp);
+
+       ctx->progress_max = count;
        return ret;
 }
 
@@ -191,15 +193,18 @@ bool virtual_search_next_update_seq(struct mail_search_context *ctx)
 
        recs = array_get(&vctx->records, &count);
        if (vctx->next_record_idx < count) {
+               /* go through potential results first */
                ctx->seq = recs[vctx->next_record_idx++].virtual_seq - 1;
                if (!index_storage_search_next_update_seq(ctx))
                        i_unreached();
+               ctx->progress_cur = vctx->next_record_idx;
                return TRUE;
        }
 
        if (ctx->sort_program != NULL &&
            seq_range_array_iter_nth(&vctx->result_iter,
                                     vctx->next_result_n, &ctx->seq)) {
+               /* this is known to match fully */
                search_args_set_full_match(ctx->args->args);
                vctx->next_result_n++;
                return TRUE;