]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imapc: Don't flush prefetch FETCH command before it has mail_prefetch_count number...
authorTimo Sirainen <tss@iki.fi>
Wed, 11 Mar 2015 12:39:52 +0000 (14:39 +0200)
committerTimo Sirainen <tss@iki.fi>
Wed, 11 Mar 2015 12:39:52 +0000 (14:39 +0200)
src/lib-storage/index/imapc/imapc-mail-fetch.c

index b54ad3d325d3641db925edc9a1b614fb4600e9e1..c104fe9c1c884cc3bfb05a1219e032173d696ee7 100644 (file)
@@ -146,7 +146,19 @@ imapc_mail_delayed_send_or_merge(struct imapc_mail *mail, string_t *str)
        }
        array_append(&mbox->pending_fetch_request->mails, &mail, 1);
 
-       if (mbox->to_pending_fetch_send == NULL) {
+       if (mbox->to_pending_fetch_send == NULL &&
+           array_count(&mbox->pending_fetch_request->mails) >
+                               mbox->box.storage->set->mail_prefetch_count) {
+               /* we're now prefetching the maximum number of mails. this
+                  most likely means that we need to flush out the command now
+                  before sending anything else. delay it a little bit though
+                  in case the sending code doesn't actually use
+                  mail_prefetch_count and wants to fetch more.
+
+                  note that we don't want to add this timeout too early,
+                  because we want to optimize the maximum number of messages
+                  placed into a single FETCH. even without timeout the command
+                  gets flushed by imapc_mail_fetch() call. */
                mbox->to_pending_fetch_send =
                        timeout_add_short(0, imapc_mail_fetch_flush, mbox);
        }
@@ -397,7 +409,8 @@ void imapc_mail_fetch_flush(struct imapc_mailbox *mbox)
        imapc_command_send(cmd, str_c(mbox->pending_fetch_cmd));
 
        mbox->pending_fetch_request = NULL;
-       timeout_remove(&mbox->to_pending_fetch_send);
+       if (mbox->to_pending_fetch_send != NULL)
+               timeout_remove(&mbox->to_pending_fetch_send);
        str_truncate(mbox->pending_fetch_cmd, 0);
 }