# HG changeset patch # User Timo Sirainen # Date 1190457877 -10800 # Node ID a62923d3c969265327496eb98cc3a2b25779a6e4 # Parent cbfce8bbc9171d3b531b4bc233db2547578ff052 Don't sync mailbox immediately when committing transactions. When it's done later, make sure we sync the mailbox if there are pending changes in transaction log. diff -r cbfce8bbc917 -r a62923d3c969 src/lib-storage/index/maildir/maildir-sync.c --- a/src/lib-storage/index/maildir/maildir-sync.c Sat Sep 22 13:42:25 2007 +0300 +++ b/src/lib-storage/index/maildir/maildir-sync.c Sat Sep 22 13:44:37 2007 +0300 @@ -659,27 +659,43 @@ maildir_uidlist_get_next_uid(ctx->mbox->uidlist); } +static int maildir_sync_get_changes(struct maildir_sync_context *ctx, + bool *new_changed_r, bool *cur_changed_r) +{ + enum mail_index_sync_flags flags = 0; + + if (maildir_sync_quick_check(ctx->mbox, ctx->new_dir, ctx->cur_dir, + new_changed_r, cur_changed_r) < 0) + return -1; + + if (*new_changed_r || *cur_changed_r) + return 1; + + if (move_recent_messages(ctx)) { + *new_changed_r = TRUE; + return 1; + } + + if (!ctx->mbox->ibox.keep_recent) + flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT; + + return mail_index_sync_have_any(ctx->mbox->ibox.index, flags) ? 1 : 0; +} + static int maildir_sync_context(struct maildir_sync_context *ctx, bool forced, - bool sync_last_commit) + bool *lost_files_r) { - bool new_changed, cur_changed, full_rescan = FALSE; + bool new_changed, cur_changed; int ret; - if (sync_last_commit) { - new_changed = cur_changed = FALSE; - } else if (!forced) { - if (maildir_sync_quick_check(ctx->mbox, - ctx->new_dir, ctx->cur_dir, - &new_changed, &cur_changed) < 0) - return -1; + *lost_files_r = FALSE; - if (!new_changed && !cur_changed) { - if (!move_recent_messages(ctx)) - return 1; - new_changed = TRUE; - } - } else { + if (forced) new_changed = cur_changed = TRUE; + else { + ret = maildir_sync_get_changes(ctx, &new_changed, &cur_changed); + if (ret <= 0) + return ret; } /* @@ -781,42 +797,24 @@ if (ret < 0) return -1; if (ret == 0) - full_rescan = TRUE; + *lost_files_r = TRUE; i_assert(maildir_uidlist_is_locked(ctx->mbox->uidlist)); } - ret = maildir_uidlist_sync_deinit(&ctx->uidlist_sync_ctx); - return ret < 0 ? -1 : (full_rescan ? 0 : 1); + return maildir_uidlist_sync_deinit(&ctx->uidlist_sync_ctx); } int maildir_storage_sync_force(struct maildir_mailbox *mbox) { struct maildir_sync_context *ctx; + bool lost_files; int ret; ctx = maildir_sync_context_new(mbox); - ret = maildir_sync_context(ctx, TRUE, FALSE); + ret = maildir_sync_context(ctx, TRUE, &lost_files); maildir_sync_deinit(ctx); - return ret < 0 ? -1 : 0; -} - -int maildir_sync_last_commit(struct maildir_mailbox *mbox) -{ - struct maildir_sync_context *ctx; - int ret = 0; - - if (mbox->ibox.commit_log_file_seq != 0) { - ctx = maildir_sync_context_new(mbox); - ret = maildir_sync_context(ctx, FALSE, TRUE); - maildir_sync_deinit(ctx); - } - - if (ret == 0) { - if (maildir_uidlist_update(mbox->uidlist) < 0) - ret = -1; - } - return ret < 0 ? -1 : 0; + return ret; } struct mailbox_sync_context * @@ -824,6 +822,7 @@ { struct maildir_mailbox *mbox = (struct maildir_mailbox *)box; struct maildir_sync_context *ctx; + bool lost_files; int ret = 0; if (!box->opened) @@ -835,13 +834,13 @@ mbox->ibox.sync_last_check = ioloop_time; ctx = maildir_sync_context_new(mbox); - ret = maildir_sync_context(ctx, FALSE, FALSE); + ret = maildir_sync_context(ctx, FALSE, &lost_files); maildir_sync_deinit(ctx); i_assert(!maildir_uidlist_is_locked(mbox->uidlist) || mbox->ibox.keep_locked); - if (ret == 0) { + if (lost_files) { /* lost some files from new/, see if thery're in cur/ */ ret = maildir_storage_sync_force(mbox); } diff -r cbfce8bbc917 -r a62923d3c969 src/lib-storage/index/maildir/maildir-sync.h --- a/src/lib-storage/index/maildir/maildir-sync.h Sat Sep 22 13:42:25 2007 +0300 +++ b/src/lib-storage/index/maildir/maildir-sync.h Sat Sep 22 13:44:37 2007 +0300 @@ -32,8 +32,6 @@ int maildir_sync_index_finish(struct maildir_index_sync_context **sync_ctx, bool failed, bool cancel); -int maildir_sync_last_commit(struct maildir_mailbox *mbox); - struct maildir_keywords_sync_ctx * maildir_sync_get_keywords_sync_ctx(struct maildir_index_sync_context *ctx); void maildir_sync_notify(struct maildir_sync_context *ctx); diff -r cbfce8bbc917 -r a62923d3c969 src/lib-storage/index/maildir/maildir-transaction.c --- a/src/lib-storage/index/maildir/maildir-transaction.c Sat Sep 22 13:42:25 2007 +0300 +++ b/src/lib-storage/index/maildir/maildir-transaction.c Sat Sep 22 13:44:37 2007 +0300 @@ -40,9 +40,6 @@ if (save_ctx != NULL) maildir_transaction_save_commit_post(save_ctx); - - if (ret == 0 && !syncing) - ret = maildir_sync_last_commit(mbox); return ret; }