From ea406e42cd41c596827aaebda020c06577f0bf4f Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Mon, 16 Mar 2015 13:07:33 -0700 Subject: [PATCH] Add batching support to fixUserRegistration.php Also: * Add wfWaitForSlaves() call * Clear User cache after updating registration time * Don't use empty() * Use the master for everything Bug: T92890 Change-Id: I88b97befdbd78ef12eda9a9571f6943c7b232207 --- maintenance/fixUserRegistration.php | 64 +++++++++++++++++++---------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/maintenance/fixUserRegistration.php b/maintenance/fixUserRegistration.php index 878593c71c..0120f353f5 100644 --- a/maintenance/fixUserRegistration.php +++ b/maintenance/fixUserRegistration.php @@ -33,37 +33,57 @@ class FixUserRegistration extends Maintenance { public function __construct() { parent::__construct(); $this->mDescription = "Fix the user_registration field"; + $this->setBatchSize( 1000 ); } public function execute() { - $dbr = wfGetDB( DB_SLAVE ); $dbw = wfGetDB( DB_MASTER ); - // Get user IDs which need fixing - $res = $dbr->select( 'user', 'user_id', 'user_registration IS NULL', __METHOD__ ); - foreach ( $res as $row ) { - $id = $row->user_id; - // Get first edit time - $timestamp = $dbr->selectField( - 'revision', - 'MIN(rev_timestamp)', - array( 'rev_user' => $id ), - __METHOD__ + $lastId = 0; + do { + // Get user IDs which need fixing + $res = $dbw->select( + 'user', + 'user_id', + array( + 'user_id >' . $dbw->addQuotes( $lastId ), + 'user_registration IS NULL' + ), + __METHOD__, + array( + 'LIMIT' => $this->mBatchSize, + 'ORDER BY user_id ASC', + ) ); - // Update - if ( !empty( $timestamp ) ) { - $dbw->update( - 'user', - array( 'user_registration' => $timestamp ), - array( 'user_id' => $id ), + foreach ( $res as $row ) { + $id = $row->user_id; + $lastId = $id; + // Get first edit time + $timestamp = $dbw->selectField( + 'revision', + 'MIN(rev_timestamp)', + array( 'rev_user' => $id ), __METHOD__ ); - $this->output( "$id $timestamp\n" ); - } else { - $this->output( "$id NULL\n" ); + // Update + if ( $timestamp !== false ) { + $dbw->update( + 'user', + array( 'user_registration' => $timestamp ), + array( 'user_id' => $id ), + __METHOD__ + ); + $user = User::newFromId( $id ); + $user->invalidateCache(); + $this->output( "Set registration for #$id to $timestamp\n" ); + } else { + $this->output( "Could not find registration for #$id NULL\n" ); + } } - } - $this->output( "\n" ); + $this->output( "Waiting for slaves..." ); + wfWaitForSlaves(); + $this->output( " done.\n" ); + } while ( $res->numRows() ); } } -- 2.20.1