From: Marco Bettini Date: Thu, 9 Feb 2023 11:20:02 +0000 (+0000) Subject: fts: fts_indexer_notify() - Retrofit notify_progress() X-Git-Tag: 2.4.0~2733 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0979ff999c8d93140485bc00379fb2f5c80ed91;p=thirdparty%2Fdovecot%2Fcore.git fts: fts_indexer_notify() - Retrofit notify_progress() Also change the timeout from INDEXER_NOTIFY_INTERVAL_SECS to MAIL_STORAGE_NOTIFY_INTERVAL_SECS --- diff --git a/src/plugins/fts/fts-indexer.c b/src/plugins/fts/fts-indexer.c index 4372ab8108..540bf3746b 100644 --- a/src/plugins/fts/fts-indexer.c +++ b/src/plugins/fts/fts-indexer.c @@ -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) diff --git a/src/plugins/fts/fts-storage.c b/src/plugins/fts/fts-storage.c index c6e0f3789a..d54a92495f 100644 --- a/src/plugins/fts/fts-storage.c +++ b/src/plugins/fts/fts-storage.c @@ -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)