Skip to content

Commit 56fb5d0

Browse files
committed
mailbox_notify_changes(): Delay sending notifications for 500 msecs.
If the notification is done immediately, IDLE may not notice the change because it's not finished yet. --HG-- branch : HEAD
1 parent 83fa91a commit 56fb5d0

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/lib-storage/index/index-mailbox-check.c

+16-14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <fcntl.h>
1010
#include <sys/stat.h>
1111

12+
#define NOTIFY_DELAY_MSECS 500
13+
1214
struct index_notify_file {
1315
struct index_notify_file *next;
1416

@@ -25,9 +27,8 @@ static void check_timeout(struct index_mailbox *ibox)
2527
{
2628
struct index_notify_file *file;
2729
struct stat st;
28-
bool notify;
30+
bool notify = FALSE;
2931

30-
notify = ibox->notify_pending;
3132
for (file = ibox->notify_files; file != NULL; file = file->next) {
3233
if (stat(file->path, &st) == 0 &&
3334
file->last_stamp != st.st_mtime) {
@@ -37,23 +38,25 @@ static void check_timeout(struct index_mailbox *ibox)
3738
}
3839

3940
if (notify) {
40-
ibox->notify_last_sent = ioloop_time;
41-
ibox->notify_pending = FALSE;
41+
if (ibox->notify_delay_to != NULL)
42+
timeout_remove(&ibox->notify_delay_to);
4243
ibox->box.notify_callback(&ibox->box, ibox->box.notify_context);
4344
}
4445
}
4546

47+
static void notify_delay_callback(struct index_mailbox *ibox)
48+
{
49+
ibox->box.notify_callback(&ibox->box, ibox->box.notify_context);
50+
}
51+
4652
static void notify_callback(struct index_mailbox *ibox)
4753
{
4854
timeout_reset(ibox->notify_to);
4955

50-
/* don't notify more often than once a second */
51-
if (ioloop_time > ibox->notify_last_sent) {
52-
ibox->notify_last_sent = ioloop_time;
53-
ibox->notify_pending = FALSE;
54-
ibox->box.notify_callback(&ibox->box, ibox->box.notify_context);
55-
} else {
56-
ibox->notify_pending = TRUE;
56+
if (ibox->notify_delay_to == NULL) {
57+
ibox->notify_delay_to =
58+
timeout_add(NOTIFY_DELAY_MSECS,
59+
notify_delay_callback, ibox);
5760
}
5861
}
5962

@@ -95,9 +98,6 @@ void index_mailbox_check_remove_all(struct index_mailbox *ibox)
9598
struct index_notify_file *file;
9699
struct index_notify_io *aio;
97100

98-
/* reset notify stamp */
99-
ibox->notify_last_sent = 0;
100-
101101
while (ibox->notify_files != NULL) {
102102
file = ibox->notify_files;
103103
ibox->notify_files = file->next;
@@ -114,6 +114,8 @@ void index_mailbox_check_remove_all(struct index_mailbox *ibox)
114114
i_free(aio);
115115
}
116116

117+
if (ibox->notify_delay_to != NULL)
118+
timeout_remove(&ibox->notify_delay_to);
117119
if (ibox->notify_to != NULL)
118120
timeout_remove(&ibox->notify_to);
119121
}

src/lib-storage/index/index-storage.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ struct index_mailbox {
4343
struct mail_cache *cache;
4444
struct mail_vfuncs *mail_vfuncs;
4545

46-
struct timeout *notify_to;
46+
struct timeout *notify_to, *notify_delay_to;
4747
struct index_notify_file *notify_files;
4848
struct index_notify_io *notify_ios;
49-
time_t notify_last_check, notify_last_sent;
49+
time_t notify_last_check;
5050

5151
time_t next_lock_notify; /* temporary */
5252
enum mailbox_lock_notify_type last_notify_type;
@@ -62,7 +62,6 @@ struct index_mailbox {
6262

6363
/* we've discovered there aren't enough permissions to modify mailbox */
6464
unsigned int backend_readonly:1;
65-
unsigned int notify_pending:1;
6665
unsigned int move_to_memory:1;
6766
};
6867

0 commit comments

Comments
 (0)