]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Avoid rebuilding the whole mailbox list index when one mailbox changes.
authorTimo Sirainen <tss@iki.fi>
Tue, 15 Apr 2014 13:13:28 +0000 (15:13 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 15 Apr 2014 13:13:28 +0000 (15:13 +0200)
src/lib-storage/list/mailbox-list-index-status.c
src/lib-storage/list/mailbox-list-index.h

index 5fbc51e6e4c662f175a1386103b48cfaf8ea0154..802d908cf5401748951fac9a800d020f703573e1 100644 (file)
@@ -53,7 +53,10 @@ index_list_open_view(struct mailbox *box, struct mail_index_view **view_r,
 
        if (ret != 0) {
                /* error / mailbox has changed. we'll need to sync it. */
-               mailbox_list_index_refresh_later(box->list);
+               if (ret < 0)
+                       mailbox_list_index_refresh_later(box->list);
+               else
+                       ilist->index_last_check_changed = TRUE;
                mail_index_view_close(&view);
                return ret < 0 ? -1 : 0;
        }
@@ -366,10 +369,14 @@ static int index_list_update_mailbox(struct mailbox *box)
        list_view = mail_index_view_open(ilist->index);
        if (!index_list_update_fill_changes(box, list_view, &changes))
                ret = -1;
-       else if (!index_list_has_changed(box, list_view, &changes))
-               ret = 0;
-       else
+       else if (index_list_has_changed(box, list_view, &changes))
                ret = 1;
+       else {
+               /* if backend state changed on the last check, update it here
+                  now. we probably don't need to bother checking again if the
+                  state had changed? */
+               ret = ilist->index_last_check_changed;
+       }
        mail_index_view_close(&list_view);
        if (ret <= 0) {
                if (ret < 0)
@@ -394,9 +401,10 @@ static int index_list_update_mailbox(struct mailbox *box)
 
        if (!index_list_update_fill_changes(box, list_view, &changes))
                mailbox_list_index_refresh_later(box->list);
-       else if (index_list_has_changed(box, list_view, &changes)) {
+       else {
                ilist->updating_status = TRUE;
-               index_list_update(box, list_view, list_trans, &changes);
+               if (index_list_has_changed(box, list_view, &changes))
+                       index_list_update(box, list_view, list_trans, &changes);
                if (box->v.list_index_update_sync != NULL) {
                        box->v.list_index_update_sync(box, list_trans,
                                                      changes.seq);
@@ -408,6 +416,7 @@ static int index_list_update_mailbox(struct mailbox *box)
                mailbox_set_index_error(box);
                return -1;
        }
+       ilist->index_last_check_changed = FALSE;
        return 0;
 }
 
index 54a33f80d9d2d2f53c326d485a2832419d36c88f..3303953e60e0a5c2fa2e29b76f16dea9e89b521a 100644 (file)
@@ -107,6 +107,7 @@ struct mailbox_list_index {
        unsigned int syncing:1;
        unsigned int updating_status:1;
        unsigned int has_backing_store:1;
+       unsigned int index_last_check_changed:1;
 };
 
 struct mailbox_list_index_iterate_context {