From 0e5819a061034f1636b124c03a89f67d37c852b1 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sat, 17 Jan 2009 12:30:54 -0500 Subject: [PATCH] quota plugin optimization: Don't look up quota values every time when iterating quota roots. --HG-- branch : HEAD --- src/plugins/quota/quota-private.h | 3 +++ src/plugins/quota/quota.c | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/plugins/quota/quota-private.h b/src/plugins/quota/quota-private.h index 30136b0b57..24b6f55779 100644 --- a/src/plugins/quota/quota-private.h +++ b/src/plugins/quota/quota-private.h @@ -100,6 +100,9 @@ struct quota_root { may change these by reading the limits elsewhere (e.g. Maildir++, FS quota) */ int64_t bytes_limit, count_limit; + /* 1 = quota root has resources and should be returned when iterating + quota roots, 0 = not, -1 = unknown. */ + int resource_ret; /* Module-specific contexts. See quota_module_id. */ ARRAY_DEFINE(quota_module_contexts, void); diff --git a/src/plugins/quota/quota.c b/src/plugins/quota/quota.c index f61cafcf27..9f4fe37711 100644 --- a/src/plugins/quota/quota.c +++ b/src/plugins/quota/quota.c @@ -142,6 +142,7 @@ quota_root_init(struct quota_root_settings *root_set, struct quota *quota) const char *const *tmp; root = root_set->backend->v.alloc(); + root->resource_ret = -1; root->pool = pool_alloconly_create("quota root", 512); root->set = root_set; root->quota = quota; @@ -622,14 +623,18 @@ struct quota_root *quota_root_iter_next(struct quota_root_iter *iter) if (!quota_root_is_visible(roots[iter->i], iter->box, FALSE)) continue; - ret = quota_get_resource(roots[iter->i], "", - QUOTA_NAME_STORAGE_KILOBYTES, - &value, &limit); + ret = roots[iter->i]->resource_ret; + if (ret == -1) { + ret = quota_get_resource(roots[iter->i], "", + QUOTA_NAME_STORAGE_KILOBYTES, + &value, &limit); + } if (ret == 0) { ret = quota_get_resource(roots[iter->i], "", QUOTA_NAME_MESSAGES, &value, &limit); } + roots[iter->i]->resource_ret = ret; if (ret > 0) { root = roots[iter->i]; break; -- 2.47.3