From 825b2b9ab9ae91230f76a0169b72c5e5d9d0e2b0 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Fri, 20 Feb 2015 04:35:49 -0500
Subject: [PATCH] Fix performance of rcube_db_mysql::get_variable()
---
CHANGELOG | 1 +
program/lib/Roundcube/rcube_db_mysql.php | 23 ++++++++++++++++-------
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index 84d4f9a..aed7288 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -8,6 +8,7 @@
- Fix setting max packet size for DB caches and check packet size also in shared cache
- Fix needless security warning on BMP attachments display (#1490282)
- Fix handling of some improper constructs in format=flowed text as per the RFC3676[4.5] (#1490284)
+- Fix performance of rcube_db_mysql::get_variable()
RELEASE 1.1.0
-------------
diff --git a/program/lib/Roundcube/rcube_db_mysql.php b/program/lib/Roundcube/rcube_db_mysql.php
index 0e85b0f..067e94b 100644
--- a/program/lib/Roundcube/rcube_db_mysql.php
+++ b/program/lib/Roundcube/rcube_db_mysql.php
@@ -161,15 +161,24 @@
{
if (!isset($this->variables)) {
$this->variables = array();
-
- $result = $this->query('SHOW VARIABLES');
-
- while ($row = $this->fetch_array($result)) {
- $this->variables[$row[0]] = $row[1];
- }
}
- return isset($this->variables[$varname]) ? $this->variables[$varname] : $default;
+ if (array_key_exists($varname, $this->variables)) {
+ return $this->variables[$varname];
+ }
+
+ $result = $this->query('SHOW VARIABLES LIKE ?', $varname);
+
+ while ($row = $this->fetch_array($result)) {
+ $this->variables[$row[0]] = $row[1];
+ }
+
+ // not found, use default
+ if (!isset($this->variables[$varname])) {
+ $this->variables[$varname] = $default;
+ }
+
+ return $this->variables[$varname];
}
/**
--
Gitblit v1.9.1