]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: Don't get message sizes when updating mailbox that ignores quotas.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 9 Aug 2016 15:06:25 +0000 (18:06 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 10 Aug 2016 16:09:32 +0000 (19:09 +0300)
Nothing is done with the size anyway.

src/plugins/quota/quota-private.h
src/plugins/quota/quota.c

index c28207f195e0eec6fde7613cbe537bff8a298e9e..340438452442ac3e34afbde0522f67e59eef9cf8 100644 (file)
@@ -182,6 +182,8 @@ struct quota_transaction_context {
        bool sync_transaction:1;
        /* TRUE if all roots have auto_updating=TRUE */
        bool auto_updating:1;
+       /* Quota doesn't need to be updated within this transaction. */
+       bool no_quota_updates:1;
 };
 
 /* Register storage to all user's quota roots. */
index d7b634f433f44113348410fa46da83fb976225a9..cbec924cff2b51bd20d2a8595f27a1be77b4203d 100644 (file)
@@ -399,12 +399,15 @@ void quota_deinit(struct quota **_quota)
 static int quota_root_get_rule_limits(struct quota_root *root,
                                      const char *mailbox_name,
                                      uint64_t *bytes_limit_r,
-                                     uint64_t *count_limit_r)
+                                     uint64_t *count_limit_r,
+                                     bool *ignored_r)
 {
        struct quota_rule *rule;
        int64_t bytes_limit, count_limit;
        bool enabled;
 
+       *ignored_r = FALSE;
+
        if (!root->set->force_default_rule) {
                if (root->backend.v.init_limits != NULL) {
                        if (root->backend.v.init_limits(root) < 0)
@@ -429,6 +432,7 @@ static int quota_root_get_rule_limits(struct quota_root *root,
                } else {
                        bytes_limit = 0;
                        count_limit = 0;
+                       *ignored_r = TRUE;
                }
        }
 
@@ -671,7 +675,7 @@ int quota_get_resource(struct quota_root *root, const char *mailbox_name,
                       const char *name, uint64_t *value_r, uint64_t *limit_r)
 {
        uint64_t bytes_limit, count_limit;
-       bool kilobytes = FALSE;
+       bool ignored, kilobytes = FALSE;
        int ret;
 
        *value_r = *limit_r = 0;
@@ -688,7 +692,8 @@ int quota_get_resource(struct quota_root *root, const char *mailbox_name,
                return ret;
 
        if (quota_root_get_rule_limits(root, mailbox_name,
-                                      &bytes_limit, &count_limit) < 0)
+                                      &bytes_limit, &count_limit,
+                                      &ignored) < 0)
                return -1;
 
        if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0)
@@ -785,13 +790,14 @@ static int quota_transaction_set_limits(struct quota_transaction_context *ctx)
        const char *mailbox_name;
        unsigned int i, count;
        uint64_t bytes_limit, count_limit, current, limit, diff;
-       bool use_grace;
+       bool use_grace, ignored;
        int ret;
 
        ctx->limits_set = TRUE;
        mailbox_name = mailbox_get_vname(ctx->box);
        /* use quota_grace only for LDA/LMTP */
        use_grace = (ctx->box->flags & MAILBOX_FLAG_POST_SESSION) != 0;
+       ctx->no_quota_updates = TRUE;
 
        /* find the lowest quota limits from all roots and use them */
        roots = array_get(&ctx->quota->roots, &count);
@@ -800,11 +806,13 @@ static int quota_transaction_set_limits(struct quota_transaction_context *ctx)
                        continue;
 
                if (quota_root_get_rule_limits(roots[i], mailbox_name,
-                                              &bytes_limit,
-                                              &count_limit) < 0) {
+                                              &bytes_limit, &count_limit,
+                                              &ignored) < 0) {
                        ctx->failed = TRUE;
                        return -1;
                }
+               if (!ignored)
+                       ctx->no_quota_updates = FALSE;
 
                if (bytes_limit > 0) {
                        ret = quota_get_resource(roots[i], mailbox_name,
@@ -1094,6 +1102,14 @@ int quota_try_alloc(struct quota_transaction_context *ctx,
        uoff_t size;
        int ret;
 
+       if (!ctx->limits_set) {
+               if (quota_transaction_set_limits(ctx) < 0)
+                       return -1;
+       }
+
+       if (ctx->no_quota_updates)
+               return 1;
+
        if (mail_get_physical_size(mail, &size) < 0) {
                i_error("quota: Failed to get mail size (box=%s, uid=%u): %s",
                        mail->box->vname, mail->uid,
@@ -1124,6 +1140,8 @@ int quota_test_alloc(struct quota_transaction_context *ctx,
                if (quota_transaction_set_limits(ctx) < 0)
                        return -1;
        }
+       if (ctx->no_quota_updates)
+               return 1;
        /* this is a virtual function mainly for trash plugin and similar,
           which may automatically delete mails to stay under quota. */
        return ctx->quota->set->test_alloc(ctx, size, too_large_r);
@@ -1134,6 +1152,7 @@ static int quota_default_test_alloc(struct quota_transaction_context *ctx,
 {
        struct quota_root *const *roots;
        unsigned int i, count;
+       bool ignore;
        int ret;
 
        *too_large_r = FALSE;
@@ -1151,7 +1170,8 @@ static int quota_default_test_alloc(struct quota_transaction_context *ctx,
 
                ret = quota_root_get_rule_limits(roots[i],
                                                 mailbox_get_vname(ctx->box),
-                                                &bytes_limit, &count_limit);
+                                                &bytes_limit, &count_limit,
+                                                &ignore);
                if (ret < 0)
                        return -1;