]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
indexer: Send completion% status updates to clients.
authorTimo Sirainen <tss@iki.fi>
Wed, 31 Aug 2011 09:02:29 +0000 (12:02 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 31 Aug 2011 09:02:29 +0000 (12:02 +0300)
src/indexer/indexer-queue.c
src/indexer/master-connection.c
src/indexer/worker-connection.c

index 8caba4c72c1ec0a3d0848c873aff8c1c881d1611..b020fa4e46403df57f5b0a898a3a5694c17e1328 100644 (file)
@@ -181,7 +181,6 @@ static void indexer_queue_request_status_int(struct indexer_queue *queue,
        if (request->contexts != NULL) {
                for (i = 0; request->contexts[i] != NULL; i++)
                        queue->callback(percentage, request->contexts[i]);
-               i_free(request->contexts);
        }
 }
 
@@ -203,6 +202,7 @@ void indexer_queue_request_finish(struct indexer_queue *queue,
        *_request = NULL;
 
        indexer_queue_request_status_int(queue, request, success ? 100 : -1);
+       i_free(request->contexts);
        i_free(request->username);
        i_free(request->mailbox);
        i_free(request);
index 5feecd923646db56403e1594059400092bd1f15d..8cf9eca10a296bf5a57c3e9587c208bcf580c3c1 100644 (file)
@@ -50,7 +50,8 @@ indexer_worker_refresh_proctitle(const char *username, const char *mailbox,
        }
 }
 
-static int index_mailbox_precache(struct mailbox *box)
+static int
+index_mailbox_precache(struct master_connection *conn, struct mailbox *box)
 {
        struct mail_storage *storage = mailbox_get_storage(box);
        const char *username = mail_storage_get_user(storage)->username;
@@ -62,7 +63,8 @@ static int index_mailbox_precache(struct mailbox *box)
        struct mail *mail;
        struct mailbox_metadata metadata;
        uint32_t seq;
-       unsigned int counter = 0, max;
+       char percentage_str[2+1+1];
+       unsigned int counter = 0, max, percentage, percentage_sent = 0;
        int ret = 0;
 
        if (mailbox_get_metadata(box, MAILBOX_METADATA_PRECACHE_FIELDS,
@@ -84,6 +86,17 @@ static int index_mailbox_precache(struct mailbox *box)
        while (mailbox_search_next(ctx, &mail)) {
                mail_precache(mail);
                if (++counter % 100 == 0) {
+                       percentage = counter*100 / max;
+                       if (percentage != percentage_sent) {
+                               i_assert(percentage < 100);
+
+                               percentage_sent = percentage;
+                               i_snprintf(percentage_str,
+                                          sizeof(percentage_str), "%u\n",
+                                          percentage);
+                               (void)write_full(conn->fd, percentage_str,
+                                                strlen(percentage_str));
+                       }
                        indexer_worker_refresh_proctitle(username, box_vname,
                                                         counter, max);
                }
@@ -99,8 +112,10 @@ static int index_mailbox_precache(struct mailbox *box)
        return ret;
 }
 
-static int index_mailbox(struct mail_user *user, const char *mailbox,
-                        unsigned int max_recent_msgs, const char *what)
+static int
+index_mailbox(struct master_connection *conn, struct mail_user *user,
+             const char *mailbox, unsigned int max_recent_msgs,
+             const char *what)
 {
        struct mail_namespace *ns;
        struct mailbox *box;
@@ -116,8 +131,6 @@ static int index_mailbox(struct mail_user *user, const char *mailbox,
                return -1;
        }
 
-       /* FIXME: the current lib-storage API doesn't allow sending
-          "n% competed" notifications */
        box = mailbox_alloc(ns->list, mailbox, 0);
        if (max_recent_msgs != 0) {
                /* index only if there aren't too many recent messages.
@@ -151,7 +164,7 @@ static int index_mailbox(struct mail_user *user, const char *mailbox,
                }
                ret = -1;
        } else if (strchr(what, 'i') != NULL) {
-               index_mailbox_precache(box);
+               index_mailbox_precache(conn, box);
        }
        mailbox_free(&box);
        return ret;
@@ -186,7 +199,8 @@ master_connection_input_line(struct master_connection *conn, const char *line)
                ret = -1;
        } else {
                indexer_worker_refresh_proctitle(user->username, args[1], 0, 0);
-               ret = index_mailbox(user, args[1], max_recent_msgs, args[3]);
+               ret = index_mailbox(conn, user, args[1],
+                                   max_recent_msgs, args[3]);
                indexer_worker_refresh_proctitle(NULL, NULL, 0, 0);
                mail_user_unref(&user);
                mail_storage_service_user_free(&service_user);
index 7cd54d704d2f30847e24961fc18157cbc8556262..5423e64166eba653fd2a0213e53eb8ad477abd64 100644 (file)
@@ -133,10 +133,12 @@ worker_connection_input_line(struct worker_connection *conn, const char *line)
        contextp = array_idx(&conn->request_contexts,
                             aqueue_idx(conn->request_queue, 0));
        context = *contextp;
-       aqueue_delete_tail(conn->request_queue);
-
-       if (aqueue_count(conn->request_queue) == 0)
-               i_free_and_null(conn->request_username);
+       if (percentage < 0 || percentage == 100) {
+               /* the request is finished */
+               aqueue_delete_tail(conn->request_queue);
+               if (aqueue_count(conn->request_queue) == 0)
+                       i_free_and_null(conn->request_username);
+       }
 
        conn->callback(percentage, context);
        return 0;