]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Move progress notification from search_more_with_mail() to mailbox_searc...
authorMarco Bettini <marco.bettini@open-xchange.com>
Wed, 8 Feb 2023 10:01:04 +0000 (10:01 +0000)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 22 May 2023 09:21:43 +0000 (09:21 +0000)
This allows to cover more cases, notably also the search progress
in FILTER=SIEVE extension

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

index ad01a41a1c12b072e13f88ffe6ac63ccea77d3dc..d62000506a15ae9e52a8df3af97ab6ccd707a2db 100644 (file)
@@ -24,7 +24,6 @@ struct index_search_context {
        struct mail_thread_context *thread_ctx;
        pool_t temp_pool;
 
-       struct timeval search_start_time, last_notify;
        struct timeval last_nonblock_timeval;
        struct timeval interrupt_start_time;
        unsigned long long cost, next_time_check_cost;
index 786d8eae1e5ac362188f99df174fe23e3da3b5cb..930f810f0a80f4642a45a9cc28c18d68428176dd 100644 (file)
@@ -25,8 +25,6 @@
 
 #include <ctype.h>
 
-#define SEARCH_NOTIFY_INTERVAL_SECS 10
-
 #define SEARCH_COST_DENTRY 3ULL
 #define SEARCH_COST_ATTR 1ULL
 #define SEARCH_COST_FILES_READ 25ULL
@@ -1554,38 +1552,6 @@ static int search_match_next(struct index_search_context *ctx)
        return ret;
 }
 
-static void index_storage_search_notify(struct mailbox *box,
-                                       struct index_search_context *ctx)
-{
-       float percentage;
-       unsigned int msecs, secs;
-
-       if (ctx->last_notify.tv_sec == 0) {
-               /* set the search time in here, in case a plugin
-                  already spent some time indexing the mailbox */
-               ctx->search_start_time = ioloop_timeval;
-       } else if (box->storage->callbacks.notify_ok != NULL &&
-                  !ctx->mail_ctx.progress_hidden) {
-               percentage = ctx->mail_ctx.progress_cur * 100.0 /
-                       ctx->mail_ctx.progress_max;
-               msecs = timeval_diff_msecs(&ioloop_timeval,
-                                          &ctx->search_start_time);
-               secs = (msecs / (percentage / 100.0) - msecs) / 1000;
-
-               T_BEGIN {
-                       const char *text;
-
-                       text = t_strdup_printf("Searched %d%% of the mailbox, "
-                                              "ETA %d:%02d", (int)percentage,
-                                              secs/60, secs%60);
-                       box->storage->callbacks.
-                               notify_ok(box, text,
-                                         box->storage->callback_context);
-               } T_END;
-       }
-       ctx->last_notify = ioloop_timeval;
-}
-
 static bool search_would_block(struct index_search_context *ctx)
 {
        struct timeval now;
@@ -1692,10 +1658,6 @@ static int search_more_with_mail(struct index_search_context *ctx,
                return 0;
        }
 
-       if (ioloop_time - ctx->last_notify.tv_sec >=
-           SEARCH_NOTIFY_INTERVAL_SECS)
-               index_storage_search_notify(box, ctx);
-
        mail_search_args_reset(_ctx->args->args, FALSE);
 
        cost1 = search_get_cost(mail->transaction);
index 61096de2542ed7d442ced7a6fd7aae121ca0f8eb..fcbc36fa0b0fbd9590bf3961eb88a484431689e0 100644 (file)
@@ -690,6 +690,8 @@ struct mail_search_context {
        struct mailbox_header_lookup_ctx *wanted_headers;
        normalizer_func_t *normalizer;
 
+       struct timeval search_start_time, last_notify;
+
        /* if non-NULL, specifies that a search resulting is being updated.
           this can be used as a search optimization: if searched message
           already exists in search result, it's not necessary to check if
index e72ad81580d7f3ecd787821a6f138d204cf5bf3c..762c496f23ff25fc96ac5cc025fa674b704e7c06 100644 (file)
@@ -2531,6 +2531,33 @@ int mailbox_search_deinit(struct mail_search_context **_ctx)
        return ret;
 }
 
+static void mailbox_search_notify(struct mailbox *box,
+                                 struct mail_search_context *ctx)
+{
+       if (ctx->last_notify.tv_sec == 0) {
+               /* set the search time in here, in case a plugin
+                  already spent some time indexing the mailbox */
+               ctx->search_start_time = ioloop_timeval;
+       } else if (box->storage->callbacks.notify_ok != NULL &&
+                  !ctx->progress_hidden) {
+               float percentage = ctx->progress_cur * 100.0 /
+                       ctx->progress_max;
+               unsigned int msecs = timeval_diff_msecs(&ioloop_timeval,
+                                                       &ctx->search_start_time);
+               unsigned int secs = (msecs / (percentage / 100.0) - msecs) / 1000;
+
+               T_BEGIN {
+                       const char *text = t_strdup_printf(
+                               "Searched %d%% of the mailbox, ETA %d:%02d",
+                               (int)percentage, secs/60, secs%60);
+                       box->storage->callbacks.
+                               notify_ok(box, text,
+                                         box->storage->callback_context);
+               } T_END;
+       }
+       ctx->last_notify = ioloop_timeval;
+}
+
 bool mailbox_search_next(struct mail_search_context *ctx, struct mail **mail_r)
 {
        bool tryagain;
@@ -2552,6 +2579,10 @@ bool mailbox_search_next_nonblock(struct mail_search_context *ctx,
        *tryagain_r = FALSE;
 
        T_BEGIN {
+               time_t elapsed = ioloop_time - ctx->last_notify.tv_sec;
+               if (elapsed >= MAIL_STORAGE_NOTIFY_INTERVAL_SECS)
+                       mailbox_search_notify(box, ctx);
+
                ret = box->v.search_next_nonblock(ctx, mail_r, tryagain_r);
        } T_END;
        if (!ret)
index 78a4bf1058f4f51f0415ff757f6a0d2cf24fac56..6088adcac37221b905312e468febbe5ab25c2c35 100644 (file)
@@ -15,6 +15,8 @@ struct message_size;
 
 /* If some operation is taking long, call notify_ok every n seconds. */
 #define MAIL_STORAGE_STAYALIVE_SECS 15
+#define MAIL_STORAGE_NOTIFY_INTERVAL_SECS 10
+
 /* Expunge transactions are to be commited after
    every MAIL_EXPUNGE_BATCH_SIZE mails */
 #define MAIL_EXPUNGE_BATCH_SIZE 1000