X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Frebuildrecentchanges.php;h=bbf91f585e5a737e47d892a04e1fca703188279b;hb=36f4daf32c591d6b7e2435629fc6e431398b641a;hp=5df432eb7a21c7fa6a36f58a46b66053e83a1c05;hpb=fb4821adfc3ab95d9c5c0be1162139f99bfebf6c;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/rebuildrecentchanges.php b/maintenance/rebuildrecentchanges.php index 5df432eb7a..bbf91f585e 100644 --- a/maintenance/rebuildrecentchanges.php +++ b/maintenance/rebuildrecentchanges.php @@ -32,9 +32,9 @@ use MediaWiki\MediaWikiServices; * @ingroup Maintenance */ class RebuildRecentchanges extends Maintenance { - /** @var integer UNIX timestamp */ + /** @var int UNIX timestamp */ private $cutoffFrom; - /** @var integer UNIX timestamp */ + /** @var int UNIX timestamp */ private $cutoffTo; public function __construct() { @@ -61,7 +61,7 @@ class RebuildRecentchanges extends Maintenance { ( $this->hasOption( 'from' ) && !$this->hasOption( 'to' ) ) || ( !$this->hasOption( 'from' ) && $this->hasOption( 'to' ) ) ) { - $this->error( "Both 'from' and 'to' must be given, or neither", 1 ); + $this->fatalError( "Both 'from' and 'to' must be given, or neither" ); } $this->rebuildRecentChangesTablePass1(); @@ -80,6 +80,8 @@ class RebuildRecentchanges extends Maintenance { */ private function rebuildRecentChangesTablePass1() { $dbw = $this->getDB( DB_MASTER ); + $revCommentStore = new CommentStore( 'rev_comment' ); + $rcCommentStore = new CommentStore( 'rc_comment' ); if ( $this->hasOption( 'from' ) && $this->hasOption( 'to' ) ) { $this->cutoffFrom = wfTimestamp( TS_UNIX, $this->getOption( 'from' ) ); @@ -107,19 +109,20 @@ class RebuildRecentchanges extends Maintenance { 'rc_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ) ] ); - foreach ( array_chunk( $rcids, $this->mBatchSize ) as $rcidBatch ) { + foreach ( array_chunk( $rcids, $this->getBatchSize() ) as $rcidBatch ) { $dbw->delete( 'recentchanges', [ 'rc_id' => $rcidBatch ], __METHOD__ ); wfGetLBFactory()->waitForReplication(); } $this->output( "Loading from page and revision tables...\n" ); + + $commentQuery = $revCommentStore->getJoin(); $res = $dbw->select( - [ 'page', 'revision' ], + [ 'revision', 'page' ] + $commentQuery['tables'], [ 'rev_timestamp', 'rev_user', 'rev_user_text', - 'rev_comment', 'rev_minor_edit', 'rev_id', 'rev_deleted', @@ -127,19 +130,22 @@ class RebuildRecentchanges extends Maintenance { 'page_title', 'page_is_new', 'page_id' - ], + ] + $commentQuery['fields'], [ 'rev_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ), - 'rev_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ), - 'rev_page=page_id' + 'rev_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ) ], __METHOD__, - [ 'ORDER BY' => 'rev_timestamp DESC' ] + [ 'ORDER BY' => 'rev_timestamp DESC' ], + [ + 'page' => [ 'JOIN', 'rev_page=page_id' ], + ] + $commentQuery['joins'] ); $this->output( "Inserting from page and revision tables...\n" ); $inserted = 0; foreach ( $res as $row ) { + $comment = $revCommentStore->getComment( $row ); $dbw->insert( 'recentchanges', [ @@ -148,7 +154,6 @@ class RebuildRecentchanges extends Maintenance { 'rc_user_text' => $row->rev_user_text, 'rc_namespace' => $row->page_namespace, 'rc_title' => $row->page_title, - 'rc_comment' => $row->rev_comment, 'rc_minor' => $row->rev_minor_edit, 'rc_bot' => 0, 'rc_new' => $row->page_is_new, @@ -156,13 +161,12 @@ class RebuildRecentchanges extends Maintenance { 'rc_this_oldid' => $row->rev_id, 'rc_last_oldid' => 0, // is this ok? 'rc_type' => $row->page_is_new ? RC_NEW : RC_EDIT, - 'rc_source' => $row->page_is_new ? RecentChange::SRC_NEW : RecentChange::SRC_EDIT - , + 'rc_source' => $row->page_is_new ? RecentChange::SRC_NEW : RecentChange::SRC_EDIT, 'rc_deleted' => $row->rev_deleted - ], + ] + $rcCommentStore->insert( $dbw, $comment ), __METHOD__ ); - if ( ( ++$inserted % $this->mBatchSize ) == 0 ) { + if ( ( ++$inserted % $this->getBatchSize() ) == 0 ) { wfGetLBFactory()->waitForReplication(); } } @@ -252,7 +256,7 @@ class RebuildRecentchanges extends Maintenance { $lastOldId = intval( $obj->rc_this_oldid ); $lastSize = $size; - if ( ( ++$updated % $this->mBatchSize ) == 0 ) { + if ( ( ++$updated % $this->getBatchSize() ) == 0 ) { wfGetLBFactory()->waitForReplication(); } } @@ -266,25 +270,27 @@ class RebuildRecentchanges extends Maintenance { global $wgLogTypes, $wgLogRestrictions; $dbw = $this->getDB( DB_MASTER ); + $logCommentStore = new CommentStore( 'log_comment' ); + $rcCommentStore = new CommentStore( 'rc_comment' ); $this->output( "Loading from user, page, and logging tables...\n" ); + $commentQuery = $logCommentStore->getJoin(); $res = $dbw->select( - [ 'user', 'logging', 'page' ], + [ 'user', 'logging', 'page' ] + $commentQuery['tables'], [ 'log_timestamp', 'log_user', 'user_name', 'log_namespace', 'log_title', - 'log_comment', 'page_id', 'log_type', 'log_action', 'log_id', 'log_params', 'log_deleted' - ], + ] + $commentQuery['fields'], [ 'log_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ), 'log_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ), @@ -298,13 +304,14 @@ class RebuildRecentchanges extends Maintenance { [ 'page' => [ 'LEFT JOIN', [ 'log_namespace=page_namespace', 'log_title=page_title' ] ] - ] + ] + $commentQuery['joins'] ); $field = $dbw->fieldInfo( 'recentchanges', 'rc_cur_id' ); $inserted = 0; foreach ( $res as $row ) { + $comment = $logCommentStore->getComment( $row ); $dbw->insert( 'recentchanges', [ @@ -313,7 +320,6 @@ class RebuildRecentchanges extends Maintenance { 'rc_user_text' => $row->user_name, 'rc_namespace' => $row->log_namespace, 'rc_title' => $row->log_title, - 'rc_comment' => $row->log_comment, 'rc_minor' => 0, 'rc_bot' => 0, 'rc_patrolled' => 1, @@ -330,11 +336,11 @@ class RebuildRecentchanges extends Maintenance { 'rc_logid' => $row->log_id, 'rc_params' => $row->log_params, 'rc_deleted' => $row->log_deleted - ], + ] + $rcCommentStore->insert( $dbw, $comment ), __METHOD__ ); - if ( ( ++$inserted % $this->mBatchSize ) == 0 ) { + if ( ( ++$inserted % $this->getBatchSize() ) == 0 ) { wfGetLBFactory()->waitForReplication(); } } @@ -386,7 +392,7 @@ class RebuildRecentchanges extends Maintenance { __METHOD__ ); - foreach ( array_chunk( $rcids, $this->mBatchSize ) as $rcidBatch ) { + foreach ( array_chunk( $rcids, $this->getBatchSize() ) as $rcidBatch ) { $dbw->update( 'recentchanges', [ 'rc_bot' => 1 ], @@ -468,7 +474,7 @@ class RebuildRecentchanges extends Maintenance { __METHOD__ ); - if ( ( ++$updates % $this->mBatchSize ) == 0 ) { + if ( ( ++$updates % $this->getBatchSize() ) == 0 ) { wfGetLBFactory()->waitForReplication(); } }