Skip to content

Commit

Permalink
Disable sql query cache in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Narloch committed May 9, 2018
1 parent 49e681f commit 8b23be5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
11 changes: 8 additions & 3 deletions libraries/joomla/database/driver/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions libraries/joomla/database/driver/mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;');
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions libraries/joomla/database/driver/pdomysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;');
}
}
}

/**
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 8b23be5

Please sign in to comment.