]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fts: fts_indexer_notify() - Retrofit notify_progress()
authorMarco Bettini <marco.bettini@open-xchange.com>
Thu, 9 Feb 2023 11:20:02 +0000 (11:20 +0000)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 22 May 2023 09:21:43 +0000 (09:21 +0000)
Also change the timeout from INDEXER_NOTIFY_INTERVAL_SECS to
MAIL_STORAGE_NOTIFY_INTERVAL_SECS

src/plugins/fts/fts-indexer.c
src/plugins/fts/fts-storage.c

index 4372ab8108e734044404c2946846d5a1097cc300..540bf3746bf77989c1aaab6a5e3f3fbf669b9095 100644 (file)
@@ -15,7 +15,6 @@
 #include "fts-storage.h"
 #include "fts-indexer.h"
 
-#define INDEXER_NOTIFY_INTERVAL_SECS 10
 #define INDEXER_SOCKET_NAME "indexer"
 #define INDEXER_WAIT_MSECS 250
 
@@ -38,33 +37,32 @@ static void fts_indexer_idle_timeout(struct connection *conn);
 
 static void fts_indexer_notify(struct fts_indexer_context *ctx)
 {
-       unsigned long long elapsed_msecs, est_total_msecs;
-       unsigned int eta_secs;
+       struct mail_storage *storage = ctx->box->storage;
 
-       if (ioloop_time - ctx->last_notify.tv_sec < INDEXER_NOTIFY_INTERVAL_SECS)
+       if (ctx->search_start_time.tv_sec == 0) {
+               ctx->search_start_time = ioloop_timeval;
                return;
-       ctx->last_notify = ioloop_timeval;
+       }
 
-       if (ctx->box->storage->callbacks.notify_ok == NULL ||
-           ctx->percentage == 0)
-               return;
+       if (ctx->last_notify.tv_sec == 0)
+               ctx->last_notify = ctx->search_start_time;
 
-       elapsed_msecs = timeval_diff_msecs(&ioloop_timeval,
-                                          &ctx->search_start_time);
-       est_total_msecs = elapsed_msecs * 100 / ctx->percentage;
-       eta_secs = (est_total_msecs - elapsed_msecs) / 1000;
+       if (storage->callbacks.notify_progress == NULL ||
+           ioloop_time - ctx->last_notify.tv_sec < MAIL_STORAGE_NOTIFY_INTERVAL_SECS)
+               return;
 
-       T_BEGIN {
-               const char *text;
+       ctx->last_notify = ioloop_timeval;
 
-               text = t_strdup_printf("Indexed %d%% of the mailbox, "
-                                      "ETA %d:%02d", ctx->percentage,
-                                      eta_secs/60, eta_secs%60);
-               ctx->box->storage->callbacks.
-                       notify_ok(ctx->box, text,
-                                 ctx->box->storage->callback_context);
-               ctx->notified = TRUE;
-       } T_END;
+       struct mail_storage_progress_details dtl = {
+               .verb = "Indexed",
+               .total = 100,
+               .processed = ctx->percentage,
+               .start_time = ctx->search_start_time,
+               .now = ioloop_timeval,
+       };
+       storage->callbacks.notify_progress(ctx->box, &dtl,
+                                          storage->callback_context);
+       ctx->notified = TRUE;
 }
 
 static int fts_indexer_more_int(struct fts_indexer_context *ctx)
index c6e0f3789a09573641d0974b53760504fadd5a4b..d54a92495f1cf2f6755ea294dace986d9298be4e 100644 (file)
@@ -283,6 +283,7 @@ static bool fts_mailbox_build_continue(struct mail_search_context *ctx)
 
        /* indexing finished */
        mailbox_search_set_progress_hidden(ctx, FALSE);
+       mailbox_search_reset_progress_start(ctx);
        if (fts_indexer_deinit(&fctx->indexer_ctx) < 0)
                ret = -1;
        if (ret > 0)