From: Timo Sirainen Date: Fri, 29 Apr 2016 12:42:48 +0000 (+0300) Subject: quota: Optimize handling a large number of expunges. X-Git-Tag: 2.3.0.rc1~3908 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=62f2f6baf;p=thirdparty%2Fdovecot%2Fcore.git quota: Optimize handling a large number of expunges. This assumes that the mail_expunge() was called in the same order as sync_notify(), which practically means that they were both done in ascending uid order. This is usually true. --- diff --git a/src/plugins/quota/quota-storage.c b/src/plugins/quota/quota-storage.c index 17d56b4ad9..52d0e2edaa 100644 --- a/src/plugins/quota/quota-storage.c +++ b/src/plugins/quota/quota-storage.c @@ -31,6 +31,7 @@ struct quota_mailbox { struct quota_transaction_context *expunge_qt; ARRAY(uint32_t) expunge_uids; ARRAY(uoff_t) expunge_sizes; + unsigned int prev_idx; unsigned int recalculate:1; unsigned int sync_transaction_expunge:1; @@ -344,10 +345,19 @@ static void quota_mailbox_sync_notify(struct mailbox *box, uint32_t uid, i = count = 0; } else { uids = array_get(&qbox->expunge_uids, &count); - for (i = 0; i < count; i++) { + for (i = qbox->prev_idx; i < count; i++) { if (uids[i] == uid) break; } + if (i >= count) { + for (i = 0; i < qbox->prev_idx; i++) { + if (uids[i] == uid) + break; + } + if (i == qbox->prev_idx) + i = count; + } + qbox->prev_idx = i; } if (qbox->expunge_qt == NULL) {