From 053c3c5fd41f37a5a333b8746159a0fe96f46105 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Fri, 27 Jun 2014 10:18:56 -0400 Subject: [PATCH] Add $wgDebugDumpSqlLength When $wgDebugDumpSql is set, the logged queries are truncated to 500 bytes. This is often not enough if you're wanting to actually debug the queries instead of just seeing that queries were executed. Change-Id: Iad3abd20c11d647834aa5546a1a9c82916c6519f --- includes/DefaultSettings.php | 7 +++++++ includes/db/Database.php | 8 +++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 86b7533b2d..4d248acc93 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -5000,6 +5000,13 @@ $wgDebugDBTransactions = false; */ $wgDebugDumpSql = false; +/** + * Trim logged SQL queries to this many bytes. Set 0/false/null to do no + * trimming. + * @since 1.24 + */ +$wgDebugDumpSqlLength = 500; + /** * Map of string log group names to log destinations. * diff --git a/includes/db/Database.php b/includes/db/Database.php index 3207a1b5ba..e13c053806 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1028,7 +1028,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { * for a successful read query, or false on failure if $tempIgnore set */ public function query( $sql, $fname = __METHOD__, $tempIgnore = false ) { - global $wgUser, $wgDebugDBTransactions; + global $wgUser, $wgDebugDBTransactions, $wgDebugDumpSqlLength; $this->mLastQuery = $sql; if ( $this->isWriteQuery( $sql ) ) { @@ -1102,7 +1102,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { static $cnt = 0; $cnt++; - $sqlx = substr( $commentedSql, 0, 500 ); + $sqlx = $wgDebugDumpSqlLength ? substr( $commentedSql, 0, $wgDebugDumpSqlLength ) + : $commentedSql; $sqlx = strtr( $sqlx, "\t\n", ' ' ); $master = $isMaster ? 'master' : 'slave'; @@ -1133,7 +1134,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { if ( $this->ping() ) { global $wgRequestTime; wfDebug( "Reconnected\n" ); - $sqlx = substr( $commentedSql, 0, 500 ); + $sqlx = $wgDebugDumpSqlLength ? substr( $commentedSql, 0, $wgDebugDumpSqlLength ) + : $commentedSql; $sqlx = strtr( $sqlx, "\t\n", ' ' ); $elapsed = round( microtime( true ) - $wgRequestTime, 3 ); if ( $elapsed < 300 ) { -- 2.20.1