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;
#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
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;
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);
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
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;
*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)
/* 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