X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=maintenance%2FpopulateIpChanges.php;h=4becf6dd4d400d76eb3e5936358266d6b96dc92b;hp=17f49ee3581fc0196679e440eb41958d2d7ba22b;hb=70a602dde40e3694f8ef8b9c779a528c17a48f42;hpb=acfe1b50cca5ad51f723135972b629a589a733d2 diff --git a/maintenance/populateIpChanges.php b/maintenance/populateIpChanges.php index 17f49ee358..4becf6dd4d 100644 --- a/maintenance/populateIpChanges.php +++ b/maintenance/populateIpChanges.php @@ -62,9 +62,14 @@ TEXT } public function doDBUpdates() { + $dbw = $this->getDB( DB_MASTER ); + + if ( !$dbw->tableExists( 'ip_changes' ) ) { + $this->fatalError( 'ip_changes table does not exist' ); + } + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); $dbr = $this->getDB( DB_REPLICA, [ 'vslow' ] ); - $dbw = $this->getDB( DB_MASTER ); $throttle = intval( $this->getOption( 'throttle', 0 ) ); $maxRevId = intval( $this->getOption( 'max-rev-id', 0 ) ); $start = $this->getOption( 'rev-id', 0 ); @@ -72,12 +77,13 @@ TEXT ? $maxRevId : $dbw->selectField( 'revision', 'MAX(rev_id)', false, __METHOD__ ); $blockStart = $start; - $revCount = 0; + $attempted = 0; + $inserted = 0; $this->output( "Copying IP revisions to ip_changes, from rev_id $start to rev_id $end\n" ); while ( $blockStart <= $end ) { - $blockEnd = min( $blockStart + $this->mBatchSize, $end ); + $blockEnd = min( $blockStart + $this->getBatchSize(), $end ); $rows = $dbr->select( 'revision', [ 'rev_id', 'rev_timestamp', 'rev_user_text' ], @@ -88,7 +94,8 @@ TEXT $numRows = $rows->numRows(); if ( !$rows || $numRows === 0 ) { - break; + $blockStart = $blockEnd + 1; + continue; } $this->output( "...checking $numRows revisions for IP edits that need copying, " . @@ -104,16 +111,15 @@ TEXT 'ipc_hex' => IP::toHex( $row->rev_user_text ), ]; - $revCount++; + $attempted++; } } - $dbw->insert( - 'ip_changes', - $insertRows, - __METHOD__, - 'IGNORE' - ); + if ( $insertRows ) { + $dbw->insert( 'ip_changes', $insertRows, __METHOD__, 'IGNORE' ); + + $inserted += $dbw->affectedRows(); + } $lbFactory->waitForReplication(); usleep( $throttle * 1000 ); @@ -121,7 +127,7 @@ TEXT $blockStart = $blockEnd + 1; } - $this->output( "$revCount IP revisions copied.\n" ); + $this->output( "Attempted to insert $attempted IP revisions, $inserted actually done.\n" ); return true; }