]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imapc: Avoid sending unnecessary IDLEs that are immediately aborted.
authorTimo Sirainen <tss@iki.fi>
Sun, 17 Nov 2013 13:13:58 +0000 (15:13 +0200)
committerTimo Sirainen <tss@iki.fi>
Sun, 17 Nov 2013 13:13:58 +0000 (15:13 +0200)
src/lib-imap-client/imapc-client-private.h
src/lib-imap-client/imapc-client.c
src/lib-storage/index/imapc/imapc-sync.c

index 995a7d5aae2d10db14fe349b8eb23ff74c642b33..6fc1045dfb606ad7705310fbacb6c47744b70d63 100644 (file)
@@ -3,6 +3,8 @@
 
 #include "imapc-client.h"
 
+#define IMAPC_CLIENT_IDLE_SEND_DELAY_MSECS 100
+
 struct imapc_client_connection {
        struct imapc_connection *conn;
        struct imapc_client_mailbox *box;
@@ -27,6 +29,7 @@ struct imapc_client_mailbox {
        struct imapc_client *client;
        struct imapc_connection *conn;
        struct imapc_msgmap *msgmap;
+       struct timeout *to_send_idle;
 
        void (*reopen_callback)(void *context);
        void *reopen_context;
index ae5893786fb7d9648e2713ff1ce3f2d7397c0317..7ecec05ce8ca7ff33baf3179fb3337f0356c4bd0 100644 (file)
@@ -337,6 +337,8 @@ void imapc_client_mailbox_close(struct imapc_client_mailbox **_box)
        }
 
        imapc_msgmap_deinit(&box->msgmap);
+       if (box->to_send_idle != NULL)
+               timeout_remove(&box->to_send_idle);
        i_free(box);
 }
 
@@ -359,10 +361,22 @@ imapc_client_mailbox_get_msgmap(struct imapc_client_mailbox *box)
        return box->msgmap;
 }
 
-void imapc_client_mailbox_idle(struct imapc_client_mailbox *box)
+static void imapc_client_mailbox_idle_send(struct imapc_client_mailbox *box)
 {
+       timeout_remove(&box->to_send_idle);
        if (imapc_client_mailbox_is_opened(box))
                imapc_connection_idle(box->conn);
+}
+
+void imapc_client_mailbox_idle(struct imapc_client_mailbox *box)
+{
+       /* send the IDLE with a delay to avoid unnecessary IDLEs that are
+          immediately aborted */
+       if (box->to_send_idle == NULL && imapc_client_mailbox_is_opened(box)) {
+               box->to_send_idle =
+                       timeout_add_short(IMAPC_CLIENT_IDLE_SEND_DELAY_MSECS,
+                                         imapc_client_mailbox_idle_send, box);
+       }
        box->reconnect_ok = TRUE;
 }
 
index 9ce2f2baf1e131b67647f6c52d27199b3d01e063..e83cf4e025ccd4111143ce2a00ce597f81861b41 100644 (file)
@@ -458,9 +458,13 @@ imapc_mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
        }
 
        capabilities = imapc_client_get_capabilities(mbox->storage->client->client);
-       if ((capabilities & IMAPC_CAPABILITY_IDLE) == 0) {
-               /* IDLE not supported. do NOOP to get latest changes
-                  before starting sync. */
+       if ((capabilities & IMAPC_CAPABILITY_IDLE) == 0 ||
+           (flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0) {
+               /* do NOOP to make sure we have the latest changes before
+                  starting sync. this is necessary either because se don't
+                  support IDLE at all, or because we want to be sure that we
+                  have the latest changes (IDLE is started with a small delay,
+                  so we might not actually even be in IDLE right not) */
                imapc_mailbox_noop(mbox);
        }