From 13bbebaca11b376568dd96e5fe8588ea4fde56f3 Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Fri, 7 Mar 2014 08:36:28 +0000 Subject: [PATCH] Du cache pour les quota de mails par domain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (on économise autant de requete que de domaine sur le compte) --- bureau/class/m_mail.php | 14 ++++++++++++++ bureau/class/m_quota.php | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bureau/class/m_mail.php b/bureau/class/m_mail.php index 70552b57..f4d76d35 100644 --- a/bureau/class/m_mail.php +++ b/bureau/class/m_mail.php @@ -75,6 +75,7 @@ class m_mail { var $srv_pop3; var $srv_pop3s; + var $cache_domain_mail_size = array(); /* ----------------------------------------------------------------- */ /** * Constructeur @@ -110,6 +111,19 @@ class m_mail { return $obj; } + function get_total_size_for_domain($domain) { + global $db; + if (empty($this->cache_domain_mail_size)) { + $db->query("SELECT SUBSTRING_INDEX(user,'@', -1) as domain, SUM(quota_dovecot) AS sum FROM dovecot_view group by domain ;"); + while ($db->next_record() ) { + $dd = $db->f('domain'); + $this->cache_domain_mail_size[ $dd ] = $db->f('sum'); + } + } + if ( isset( $this->cache_domain_mail_size[$domain]) ) return $this->cache_domain_mail_size[$domain]; + return 0; + } + // FIXME documenter function catchall_getinfos($domain_id) { global $dom, $db; diff --git a/bureau/class/m_quota.php b/bureau/class/m_quota.php index f533503a..857a962d 100644 --- a/bureau/class/m_quota.php +++ b/bureau/class/m_quota.php @@ -459,7 +459,8 @@ class m_quota { /* sum of mailbox sizes for one domain */ function get_size_mail_sum_domain($dom) { - return $this->_get_sum_sql("SELECT SUM(quota_dovecot) AS sum FROM dovecot_view WHERE user LIKE '%@{$dom}';"); + global $mail; + return $mail->get_total_size_for_domain($dom); } /* count of mailbox sizes from all domains */