*/
require_once __DIR__ . '/Maintenance.php';
+
use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\ILBFactory;
/**
* Maintenance script that rebuilds recent changes from scratch.
$this->fatalError( "Both 'from' and 'to' must be given, or neither" );
}
- $this->rebuildRecentChangesTablePass1();
- $this->rebuildRecentChangesTablePass2();
- $this->rebuildRecentChangesTablePass3();
- $this->rebuildRecentChangesTablePass4();
- $this->rebuildRecentChangesTablePass5();
+ $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+ $this->rebuildRecentChangesTablePass1( $lbFactory );
+ $this->rebuildRecentChangesTablePass2( $lbFactory );
+ $this->rebuildRecentChangesTablePass3( $lbFactory );
+ $this->rebuildRecentChangesTablePass4( $lbFactory );
+ $this->rebuildRecentChangesTablePass5( $lbFactory );
if ( !( $this->hasOption( 'from' ) && $this->hasOption( 'to' ) ) ) {
$this->purgeFeeds();
}
/**
* Rebuild pass 1: Insert `recentchanges` entries for page revisions.
*/
- private function rebuildRecentChangesTablePass1() {
+ private function rebuildRecentChangesTablePass1( ILBFactory $lbFactory ) {
$dbw = $this->getDB( DB_MASTER );
$commentStore = CommentStore::getStore();
);
foreach ( array_chunk( $rcids, $this->getBatchSize() ) as $rcidBatch ) {
$dbw->delete( 'recentchanges', [ 'rc_id' => $rcidBatch ], __METHOD__ );
- wfGetLBFactory()->waitForReplication();
+ $lbFactory->waitForReplication();
}
$this->output( "Loading from page and revision tables...\n" );
__METHOD__
);
if ( ( ++$inserted % $this->getBatchSize() ) == 0 ) {
- wfGetLBFactory()->waitForReplication();
+ $lbFactory->waitForReplication();
}
}
}
* Rebuild pass 2: Enhance entries for page revisions with references to the previous revision
* (rc_last_oldid, rc_new etc.) and size differences (rc_old_len, rc_new_len).
*/
- private function rebuildRecentChangesTablePass2() {
+ private function rebuildRecentChangesTablePass2( ILBFactory $lbFactory ) {
$dbw = $this->getDB( DB_MASTER );
$this->output( "Updating links and size differences...\n" );
} else {
# No previous edit
$lastOldId = 0;
- $lastSize = null;
+ $lastSize = 0;
$new = 1; // probably true
}
}
$lastSize = $size;
if ( ( ++$updated % $this->getBatchSize() ) == 0 ) {
- wfGetLBFactory()->waitForReplication();
+ $lbFactory->waitForReplication();
}
}
}
/**
* Rebuild pass 3: Insert `recentchanges` entries for action logs.
*/
- private function rebuildRecentChangesTablePass3() {
- global $wgLogTypes, $wgLogRestrictions;
+ private function rebuildRecentChangesTablePass3( ILBFactory $lbFactory ) {
+ global $wgLogRestrictions, $wgFilterLogTypes;
$dbw = $this->getDB( DB_MASTER );
$commentStore = CommentStore::getStore();
+ $nonRCLogs = array_merge( array_keys( $wgLogRestrictions ),
+ array_keys( $wgFilterLogTypes ),
+ [ 'create' ] );
- $this->output( "Loading from user, page, and logging tables...\n" );
+ $this->output( "Loading from user and logging tables...\n" );
$commentQuery = $commentStore->getJoin( 'log_comment' );
$actorQuery = ActorMigration::newMigration()->getJoin( 'log_user' );
$res = $dbw->select(
- [ 'logging', 'page' ] + $commentQuery['tables'] + $actorQuery['tables'],
+ [ 'logging' ] + $commentQuery['tables'] + $actorQuery['tables'],
[
'log_timestamp',
'log_namespace',
'log_title',
- 'page_id',
+ 'log_page',
'log_type',
'log_action',
'log_id',
[
'log_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
'log_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ),
- // Some logs don't go in RC since they are private.
- // @FIXME: core/extensions also have spammy logs that don't go in RC.
- 'log_type' => array_diff( $wgLogTypes, array_keys( $wgLogRestrictions ) ),
+ // Some logs don't go in RC since they are private, or are included in the filterable log types.
+ 'log_type' => array_diff( LogPage::validTypes(), $nonRCLogs ),
],
__METHOD__,
[ 'ORDER BY' => 'log_timestamp DESC' ],
- [
- 'page' =>
- [ 'LEFT JOIN', [ 'log_namespace=page_namespace', 'log_title=page_title' ] ]
- ] + $commentQuery['joins'] + $actorQuery['joins']
+ $commentQuery['joins'] + $actorQuery['joins']
);
$field = $dbw->fieldInfo( 'recentchanges', 'rc_cur_id' );
'rc_type' => RC_LOG,
'rc_source' => RecentChange::SRC_LOG,
'rc_cur_id' => $field->isNullable()
- ? $row->page_id
- : (int)$row->page_id, // NULL => 0,
+ ? $row->log_page
+ : (int)$row->log_page, // NULL => 0,
'rc_log_type' => $row->log_type,
'rc_log_action' => $row->log_action,
'rc_logid' => $row->log_id,
);
if ( ( ++$inserted % $this->getBatchSize() ) == 0 ) {
- wfGetLBFactory()->waitForReplication();
+ $lbFactory->waitForReplication();
}
}
}
/**
* Rebuild pass 4: Mark bot and autopatrolled entries.
*/
- private function rebuildRecentChangesTablePass4() {
+ private function rebuildRecentChangesTablePass4( ILBFactory $lbFactory ) {
global $wgUseRCPatrol, $wgMiserMode;
$dbw = $this->getDB( DB_MASTER );
[ 'rc_id' => $rcidBatch ],
__METHOD__
);
- wfGetLBFactory()->waitForReplication();
+ $lbFactory->waitForReplication();
}
}
}
],
__METHOD__
);
- wfGetLBFactory()->waitForReplication();
+ $lbFactory->waitForReplication();
}
}
}
* Rebuild pass 5: Delete duplicate entries where we generate both a page revision and a log entry
* for a single action (upload only, at the moment, but potentially also move, protect, ...).
*/
- private function rebuildRecentChangesTablePass5() {
+ private function rebuildRecentChangesTablePass5( ILBFactory $lbFactory ) {
$dbw = wfGetDB( DB_MASTER );
$this->output( "Removing duplicate revision and logging entries...\n" );
);
if ( ( ++$updates % $this->getBatchSize() ) == 0 ) {
- wfGetLBFactory()->waitForReplication();
+ $lbFactory->waitForReplication();
}
}
}