Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Profiling tab for mysql (PDO) queries and disable cache in debug mode #20322

Merged
merged 1 commit into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
}