From: Umherirrender Date: Wed, 4 Sep 2019 16:11:46 +0000 (+0200) Subject: Avoid Database::tableName in WikiExporter X-Git-Tag: 1.34.0-rc.0~243^2 X-Git-Url: https://git.cyclocoop.org/admin/%7B%24admin_url%7Dmembres/import.php?a=commitdiff_plain;h=5a4d30ed09e44a10cd6fce5f6b03a864d6a253f6;p=lhc%2Fweb%2Fwiklou.git Avoid Database::tableName in WikiExporter Using * in select is not the prefered way. List all needed columns to make the use visible and to avoid issues when new fields gets added with big data. As each column name is unique there is no need to get the table name for prefixing the columns The following columns no longer selected: - log_user_text -> not used due to use of ActorMigration class - log_actor -> Add by ActorMigration class - log_comment_id -> Added by CommentStore - log_page -> Unused in the writer, the ns/title pair is used instead Move the arrays out of the loop, because there are not depending on values changing in the loop Change-Id: I140641b7ed75bc2b8db2e7612020d668f1be663b --- diff --git a/includes/export/WikiExporter.php b/includes/export/WikiExporter.php index ec0b344e3c..c1b35954e8 100644 --- a/includes/export/WikiExporter.php +++ b/includes/export/WikiExporter.php @@ -30,6 +30,7 @@ use MediaWiki\MediaWikiServices as MediaWikiServicesAlias; use MediaWiki\Storage\RevisionRecord; use Wikimedia\Rdbms\IResultWrapper; +use Wikimedia\Rdbms\IDatabase; /** * @ingroup SpecialPage Dump @@ -67,7 +68,7 @@ class WikiExporter { /** @var XmlDumpWriter */ private $writer; - /** @var Database */ + /** @var IDatabase */ protected $db; /** @var array|int */ @@ -86,7 +87,7 @@ class WikiExporter { } /** - * @param Database $db + * @param IDatabase $db * @param int|array $history One of WikiExporter::FULL, WikiExporter::CURRENT, * WikiExporter::RANGE or WikiExporter::STABLE, or an associative array: * - offset: non-inclusive offset at which to start the query @@ -303,29 +304,36 @@ class WikiExporter { if ( $cond ) { $where[] = $cond; } - # Get logging table name for logging.* clause - $logging = $this->db->tableName( 'logging' ); - $result = null; // Assuring $result is not undefined, if exception occurs early $commentQuery = CommentStore::getStore()->getJoin( 'log_comment' ); $actorQuery = ActorMigration::newMigration()->getJoin( 'log_user' ); + $tables = array_merge( + [ 'logging' ], $commentQuery['tables'], $actorQuery['tables'], [ 'user' ] + ); + $fields = [ + 'log_id', 'log_type', 'log_action', 'log_timestamp', 'log_namespace', + 'log_title', 'log_params', 'log_deleted', 'user_name' + ] + $commentQuery['fields'] + $actorQuery['fields']; + $options = [ + 'ORDER BY' => 'log_id', + 'USE INDEX' => [ 'logging' => 'PRIMARY' ], + 'LIMIT' => self::BATCH_SIZE, + ]; + $joins = [ + 'user' => [ 'JOIN', 'user_id = ' . $actorQuery['fields']['log_user'] ] + ] + $commentQuery['joins'] + $actorQuery['joins']; + $lastLogId = 0; while ( true ) { $result = $this->db->select( - array_merge( [ 'logging' ], $commentQuery['tables'], $actorQuery['tables'], [ 'user' ] ), - [ "{$logging}.*", 'user_name' ] + $commentQuery['fields'] + $actorQuery['fields'], + $tables, + $fields, array_merge( $where, [ 'log_id > ' . intval( $lastLogId ) ] ), __METHOD__, - [ - 'ORDER BY' => 'log_id', - 'USE INDEX' => [ 'logging' => 'PRIMARY' ], - 'LIMIT' => self::BATCH_SIZE, - ], - [ - 'user' => [ 'JOIN', 'user_id = ' . $actorQuery['fields']['log_user'] ] - ] + $commentQuery['joins'] + $actorQuery['joins'] + $options, + $joins ); if ( !$result->numRows() ) {