From 8b23be55dbaf935c68982bce07aaac993be5fa15 Mon Sep 17 00:00:00 2001 From: Tomasz Narloch Date: Wed, 9 May 2018 11:15:37 +0200 Subject: [PATCH] Disable sql query cache in debug mode --- libraries/joomla/database/driver/mysql.php | 11 +++++--- libraries/joomla/database/driver/mysqli.php | 12 ++++++--- libraries/joomla/database/driver/pdomysql.php | 25 +++++++++++++++++++ 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/libraries/joomla/database/driver/mysql.php b/libraries/joomla/database/driver/mysql.php index c871efdfcffe4..93b0d2f1cbd94 100644 --- a/libraries/joomla/database/driver/mysql.php +++ b/libraries/joomla/database/driver/mysql.php @@ -96,10 +96,15 @@ public function connect() // Set the character set (needed for MySQL 4.1.2+). $this->utf = $this->setUtf(); - // Turn MySQL profiling ON in debug mode: - if ($this->debug && $this->hasProfiling()) + // Disable query cache and turn profiling ON in debug mode. + if ($this->debug) { - mysql_query('SET profiling = 1;', $this->connection); + mysql_query('SET query_cache_type = 0;', $this->connection); + + if ($this->hasProfiling()) + { + mysql_query('SET profiling_history_size = 100, profiling = 1;', $this->connection); + } } } diff --git a/libraries/joomla/database/driver/mysqli.php b/libraries/joomla/database/driver/mysqli.php index e4876984b4b7d..8c84da69ecb9e 100644 --- a/libraries/joomla/database/driver/mysqli.php +++ b/libraries/joomla/database/driver/mysqli.php @@ -188,11 +188,15 @@ public function connect() // Set the character set (needed for MySQL 4.1.2+). $this->utf = $this->setUtf(); - // Turn MySQL profiling ON in debug mode: - if ($this->debug && $this->hasProfiling()) + // Disable query cache and turn profiling ON in debug mode. + if ($this->debug) { - mysqli_query($this->connection, 'SET profiling_history_size = 100;'); - mysqli_query($this->connection, 'SET profiling = 1;'); + mysqli_query($this->connection, 'SET query_cache_type = 0;'); + + if ($this->hasProfiling()) + { + mysqli_query($this->connection, 'SET profiling_history_size = 100, profiling = 1;'); + } } } diff --git a/libraries/joomla/database/driver/pdomysql.php b/libraries/joomla/database/driver/pdomysql.php index 057dadbf55fda..e9858f24aafbf 100644 --- a/libraries/joomla/database/driver/pdomysql.php +++ b/libraries/joomla/database/driver/pdomysql.php @@ -153,6 +153,17 @@ public function connect() // Set sql_mode to non_strict mode $this->connection->query("SET @@SESSION.sql_mode = '';"); + + // Disable query cache and turn profiling ON in debug mode. + if ($this->debug) + { + $this->connection->query('SET query_cache_type = 0;'); + + if ($this->hasProfiling()) + { + $this->connection->query('SET profiling_history_size = 100, profiling = 1;'); + } + } } /** @@ -571,4 +582,18 @@ public function transactionStart($asSavepoint = false) } } } + + /** + * Internal function to check if profiling is available. + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + private function hasProfiling() + { + $result = $this->setQuery("SHOW VARIABLES LIKE 'have_profiling'")->loadAssoc(); + + return isset($result); + } }