]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
indexer: index_mailbox_precache() - Move progress variables definitions closer to...
authorMarco Bettini <marco.bettini@open-xchange.com>
Tue, 16 May 2023 15:12:03 +0000 (15:12 +0000)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 22 May 2023 09:21:43 +0000 (09:21 +0000)
src/indexer/master-connection.c

index 636e26d3450ce4cbbee28dd41a1702cfd12ec86d..829986e1d9cced55566ee2e8508dee3ae22ccf75 100644 (file)
@@ -78,7 +78,6 @@ index_mailbox_precache(struct master_connection *conn, struct mailbox *box)
        struct mailbox_metadata metadata;
        uint32_t seq, first_uid = 0, last_uid = 0;
        char percentage_str[2+1+1];
-       unsigned int counter = 0, max, percentage, percentage_sent = 0;
        int ret = 0;
        struct event *index_event = event_create(box->event);
        event_add_category(index_event, &event_category_indexer_worker);
@@ -113,7 +112,9 @@ index_mailbox_precache(struct master_connection *conn, struct mailbox *box)
        /* otherwise the client doesn't receive the updates timely */
        o_stream_uncork(conn->conn.output);
 
-       max = status.messages + 1 - seq;
+       unsigned int counter = 0;
+       unsigned int percentage_sent = 0;
+       unsigned int max = status.messages + 1 - seq;
        while (mailbox_search_next(ctx, &mail)) {
                if (first_uid == 0)
                        first_uid = mail->uid;
@@ -128,10 +129,10 @@ index_mailbox_precache(struct master_connection *conn, struct mailbox *box)
                        ret = -1;
                        break;
                }
-               percentage = (++counter * 100) / max;
-               if (percentage > percentage_sent) {
+               unsigned int percentage = (++counter * 100) / max;
+               if (percentage_sent < percentage) {
+                       percentage_sent = percentage;
                        if (percentage < 100) {
-                               percentage_sent = percentage;
                                if (i_snprintf(percentage_str,
                                               sizeof(percentage_str), "%u\n",
                                               percentage) < 0)