[dovecot-cvs] dovecot/src/lib-storage/index index-search.c, 1.123, 1.124 index-storage.c, 1.97, 1.98 index-storage.h, 1.111, 1.112
tss at dovecot.org
tss at dovecot.org
Thu Dec 21 15:20:36 UTC 2006
Update of /var/lib/cvs/dovecot/src/lib-storage/index
In directory talvi:/tmp/cvs-serv27773/lib-storage/index
Modified Files:
index-search.c index-storage.c index-storage.h
Log Message:
Moved storage callbacks to struct mail_storage. If searching takes over 10
seconds, start giving estimates about when it's ready.
Index: index-search.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-search.c,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -d -r1.123 -r1.124
--- index-search.c 20 Dec 2006 21:26:36 -0000 1.123
+++ index-search.c 21 Dec 2006 15:20:31 -0000 1.124
@@ -1,6 +1,7 @@
/* Copyright (C) 2002-2006 Timo Sirainen */
#include "lib.h"
+#include "ioloop.h"
#include "array.h"
#include "istream.h"
#include "str.h"
@@ -22,6 +23,7 @@
#define TXT_INVALID_SEARCH_KEY "Invalid search key"
#define SEARCH_NONBLOCK_COUNT 20
+#define SEARCH_NOTIFY_INTERVAL_SECS 10
struct index_search_context {
struct mail_search_context mail_ctx;
@@ -35,6 +37,8 @@
pool_t hdr_pool;
const char *error;
+ struct timeval search_start_time, last_notify;
+
unsigned int failed:1;
unsigned int sorted:1;
unsigned int have_seqsets:1;
@@ -961,6 +965,39 @@
return TRUE;
}
+static void index_storage_search_notify(struct mailbox *box,
+ struct index_search_context *ctx)
+{
+ const struct mail_index_header *hdr;
+ const char *text;
+ 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) {
+ hdr = mail_index_get_header(ctx->ibox->view);
+
+ percentage = ctx->mail->seq * 100.0 / hdr->messages_count;
+ msecs = (ioloop_timeval.tv_sec -
+ ctx->search_start_time.tv_sec) * 1000 +
+ (ioloop_timeval.tv_usec -
+ ctx->search_start_time.tv_usec) / 1000;
+ secs = (msecs / (percentage / 100.0) - msecs) / 1000;
+
+ t_push();
+ 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_pop();
+ }
+ ctx->last_notify = ioloop_timeval;
+}
+
int index_storage_search_next_nonblock(struct mail_search_context *_ctx,
struct mail *mail, bool *tryagain_r)
{
@@ -980,6 +1017,10 @@
ctx->mail = mail;
ctx->imail = (struct index_mail *)mail;
+ if (ioloop_time - ctx->last_notify.tv_sec >=
+ SEARCH_NOTIFY_INTERVAL_SECS)
+ index_storage_search_notify(box, ctx);
+
while ((ret = box->v.search_next_update_seq(_ctx)) > 0) {
if (mail_set_seq(mail, _ctx->seq) < 0) {
ret = -1;
Index: index-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-storage.c,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -d -r1.97 -r1.98
--- index-storage.c 20 Dec 2006 03:16:54 -0000 1.97
+++ index-storage.c 21 Dec 2006 15:20:31 -0000 1.98
@@ -49,6 +49,9 @@
storage->storage.flags = flags;
storage->storage.lock_method = lock_method;
+ storage->storage.callbacks =
+ p_new(storage->storage.pool, struct mail_storage_callbacks, 1);
+
array_create(&storage->storage.module_contexts,
storage->storage.pool, sizeof(void *), 5);
index_storage_refcount++;
@@ -265,7 +268,7 @@
enum mailbox_lock_notify_type notify_type,
unsigned int secs_left)
{
- struct index_storage *storage = ibox->storage;
+ struct mail_storage *storage = ibox->box.storage;
const char *str;
time_t now;
@@ -440,8 +443,8 @@
{
struct index_storage *storage = (struct index_storage *) _storage;
- *storage->callbacks = *callbacks;
- storage->callback_context = context;
+ *storage->storage.callbacks = *callbacks;
+ storage->storage.callback_context = context;
}
const char *index_storage_get_last_error(struct mail_storage *storage,
Index: index-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -d -r1.111 -r1.112
--- index-storage.h 20 Dec 2006 19:23:44 -0000 1.111
+++ index-storage.h 21 Dec 2006 15:20:31 -0000 1.112
@@ -25,9 +25,6 @@
struct mail_storage storage;
const char *user; /* name of user accessing the storage */
-
- struct mail_storage_callbacks *callbacks;
- void *callback_context;
};
struct index_mailbox {
More information about the dovecot-cvs
mailing list