From 62f2f6bafd6253443a8ec9715278db60df660254 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 29 Apr 2016 15:42:48 +0300 Subject: [PATCH] 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. --- src/plugins/quota/quota-storage.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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) { -- 2.47.3