parent::__construct();
$this->addOption( 'quick', 'Force the update to be done in a single query' );
$this->addOption( 'background', 'Force replication-friendly mode; may be inefficient but
- avoids locking tables or lagging slaves with large updates;
- calculates counts on a slave if possible.
+ avoids locking tables or lagging replica DBs with large updates;
+ calculates counts on a replica DB if possible.
-Background mode will be automatically used if the server is MySQL 4.0
-(which does not support subqueries) or if multiple servers are listed
+Background mode will be automatically used if multiple servers are listed
in the load balancer, usually indicating a replication environment.' );
$this->addDescription( 'Batch-recalculate user_editcount fields from the revision table' );
}
$user = $dbw->tableName( 'user' );
$revision = $dbw->tableName( 'revision' );
- $dbver = $dbw->getServerVersion();
-
// Autodetect mode...
- $backgroundMode = wfGetLB()->getServerCount() > 1 ||
- ( $dbw instanceof DatabaseMysql );
-
if ( $this->hasOption( 'background' ) ) {
$backgroundMode = true;
} elseif ( $this->hasOption( 'quick' ) ) {
$backgroundMode = false;
+ } else {
+ $backgroundMode = wfGetLB()->getServerCount() > 1;
}
if ( $backgroundMode ) {
$this->output( "Using replication-friendly background mode...\n" );
- $dbr = $this->getDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_REPLICA );
$chunkSize = 100;
$lastUser = $dbr->selectField( 'user', 'MAX(user_id)', '', __METHOD__ );
wfWaitForSlaves();
}
} else {
- // Subselect should work on modern MySQLs etc
$this->output( "Using single-query mode...\n" );
$sql = "UPDATE $user SET user_editcount=(SELECT COUNT(*) FROM $revision WHERE rev_user=user_id)";
$dbw->query( $sql );