Finish migration to Maintenance::getBatchSize()
authorMax Semenik <maxsem.wiki@gmail.com>
Wed, 8 Nov 2017 03:35:11 +0000 (19:35 -0800)
committerMax Semenik <maxsem.wiki@gmail.com>
Wed, 8 Nov 2017 03:35:11 +0000 (19:35 -0800)
Change-Id: I02d89f71d820e4d00a39e86a30397b614bbdb432

maintenance/populateRecentChangesSource.php
maintenance/populateRevisionLength.php
maintenance/populateRevisionSha1.php
maintenance/rebuildFileCache.php
maintenance/rebuildrecentchanges.php
maintenance/refreshImageMetadata.php
maintenance/refreshLinks.php
maintenance/updateRestrictions.php

index 5d5da89..eb9797f 100644 (file)
@@ -41,6 +41,7 @@ class PopulateRecentChangesSource extends LoggedUpdateMaintenance {
 
        protected function doDBUpdates() {
                $dbw = $this->getDB( DB_MASTER );
+               $batchSize = $this->getBatchSize();
                if ( !$dbw->fieldExists( 'recentchanges', 'rc_source' ) ) {
                        $this->error( 'rc_source field in recentchanges table does not exist.' );
                }
@@ -52,9 +53,9 @@ class PopulateRecentChangesSource extends LoggedUpdateMaintenance {
                        return true;
                }
                $end = $dbw->selectField( 'recentchanges', 'MAX(rc_id)', false, __METHOD__ );
-               $end += $this->mBatchSize - 1;
+               $end += $batchSize - 1;
                $blockStart = $start;
-               $blockEnd = $start + $this->mBatchSize - 1;
+               $blockEnd = $start + $batchSize - 1;
 
                $updatedValues = $this->buildUpdateCondition( $dbw );
 
@@ -74,8 +75,8 @@ class PopulateRecentChangesSource extends LoggedUpdateMaintenance {
                        $this->output( "." );
                        wfWaitForSlaves();
 
-                       $blockStart += $this->mBatchSize;
-                       $blockEnd += $this->mBatchSize;
+                       $blockStart += $batchSize;
+                       $blockEnd += $batchSize;
                }
 
                $this->output( "\nDone.\n" );
index 0cb14c4..5de5819 100644 (file)
@@ -75,6 +75,7 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance {
        protected function doLenUpdates( $table, $idCol, $prefix, $queryInfo ) {
                $dbr = $this->getDB( DB_REPLICA );
                $dbw = $this->getDB( DB_MASTER );
+               $batchSize = $this->getBatchSize();
                $start = $dbw->selectField( $table, "MIN($idCol)", false, __METHOD__ );
                $end = $dbw->selectField( $table, "MAX($idCol)", false, __METHOD__ );
                if ( !$start || !$end ) {
@@ -85,7 +86,7 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance {
 
                # Do remaining chunks
                $blockStart = intval( $start );
-               $blockEnd = intval( $start ) + $this->mBatchSize - 1;
+               $blockEnd = intval( $start ) + $batchSize - 1;
                $count = 0;
 
                while ( $blockStart <= $end ) {
@@ -114,8 +115,8 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance {
                                $this->commitTransaction( $dbw, __METHOD__ );
                        }
 
-                       $blockStart += $this->mBatchSize;
-                       $blockEnd += $this->mBatchSize;
+                       $blockStart += $batchSize;
+                       $blockEnd += $batchSize;
                        wfWaitForSlaves();
                }
 
index f96c2ec..89eff02 100644 (file)
@@ -77,6 +77,7 @@ class PopulateRevisionSha1 extends LoggedUpdateMaintenance {
         */
        protected function doSha1Updates( $table, $idCol, $queryInfo, $prefix ) {
                $db = $this->getDB( DB_MASTER );
+               $batchSize = $this->getBatchSize();
                $start = $db->selectField( $table, "MIN($idCol)", false, __METHOD__ );
                $end = $db->selectField( $table, "MAX($idCol)", false, __METHOD__ );
                if ( !$start || !$end ) {
@@ -87,9 +88,9 @@ class PopulateRevisionSha1 extends LoggedUpdateMaintenance {
 
                $count = 0;
                # Do remaining chunk
-               $end += $this->mBatchSize - 1;
+               $end += $batchSize - 1;
                $blockStart = $start;
-               $blockEnd = $start + $this->mBatchSize - 1;
+               $blockEnd = $start + $batchSize - 1;
                while ( $blockEnd <= $end ) {
                        $this->output( "...doing $idCol from $blockStart to $blockEnd\n" );
                        $cond = "$idCol BETWEEN $blockStart AND $blockEnd
@@ -106,8 +107,8 @@ class PopulateRevisionSha1 extends LoggedUpdateMaintenance {
                        }
                        $this->commitTransaction( $db, __METHOD__ );
 
-                       $blockStart += $this->mBatchSize;
-                       $blockEnd += $this->mBatchSize;
+                       $blockStart += $batchSize;
+                       $blockEnd += $batchSize;
                        wfWaitForSlaves();
                }
 
index fe3944c..19d8d06 100644 (file)
@@ -78,6 +78,7 @@ class RebuildFileCache extends Maintenance {
                $this->output( "Building content page file cache from page {$start}!\n" );
 
                $dbr = $this->getDB( DB_REPLICA );
+               $batchSize = $this->getBatchSize();
                $overwrite = $this->hasOption( 'overwrite' );
                $start = ( $start > 0 )
                        ? $start
@@ -92,9 +93,9 @@ class RebuildFileCache extends Maintenance {
                $_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip'; // hack, no real client
 
                # Do remaining chunk
-               $end += $this->mBatchSize - 1;
+               $end += $batchSize - 1;
                $blockStart = $start;
-               $blockEnd = $start + $this->mBatchSize - 1;
+               $blockEnd = $start + $batchSize - 1;
 
                $dbw = $this->getDB( DB_MASTER );
                // Go through each page and save the output
@@ -171,8 +172,8 @@ class RebuildFileCache extends Maintenance {
                        }
                        $this->commitTransaction( $dbw, __METHOD__ ); // commit any changes (just for sanity)
 
-                       $blockStart += $this->mBatchSize;
-                       $blockEnd += $this->mBatchSize;
+                       $blockStart += $batchSize;
+                       $blockEnd += $batchSize;
                }
                $this->output( "Done!\n" );
        }
index 8003ee0..6d4a4bf 100644 (file)
@@ -109,7 +109,7 @@ 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();
                }
@@ -166,7 +166,7 @@ class RebuildRecentchanges extends Maintenance {
                                ] + $rcCommentStore->insert( $dbw, $comment ),
                                __METHOD__
                        );
-                       if ( ( ++$inserted % $this->mBatchSize ) == 0 ) {
+                       if ( ( ++$inserted % $this->getBatchSize() ) == 0 ) {
                                wfGetLBFactory()->waitForReplication();
                        }
                }
index b7f03d9..f6c0673 100644 (file)
@@ -106,7 +106,8 @@ class RefreshImageMetadata extends Maintenance {
                $error = 0;
 
                $dbw = $this->getDB( DB_MASTER );
-               if ( $this->mBatchSize <= 0 ) {
+               $batchSize = $this->getBatchSize();
+               if ( $batchSize <= 0 ) {
                        $this->error( "Batch size is too low...", 12 );
                }
 
@@ -120,7 +121,7 @@ class RefreshImageMetadata extends Maintenance {
                }
 
                $options = [
-                       'LIMIT' => $this->mBatchSize,
+                       'LIMIT' => $batchSize,
                        'ORDER BY' => 'img_name ASC',
                ];
 
@@ -194,7 +195,7 @@ class RefreshImageMetadata extends Maintenance {
                        }
                        $conds2 = [ 'img_name > ' . $dbw->addQuotes( $row->img_name ) ];
                        wfWaitForSlaves();
-               } while ( $res->numRows() === $this->mBatchSize );
+               } while ( $res->numRows() === $batchSize );
 
                $total = $upgraded + $leftAlone;
                if ( $force ) {
index b099aff..cea9e0c 100644 (file)
@@ -80,9 +80,9 @@ class RefreshLinks extends Maintenance {
                        $redir = $this->hasOption( 'redirects-only' );
                        $oldRedir = $this->hasOption( 'old-redirects-only' );
                        $this->doRefreshLinks( $start, $new, $end, $redir, $oldRedir );
-                       $this->deleteLinksFromNonexistent( null, null, $this->mBatchSize, $dfnChunkSize );
+                       $this->deleteLinksFromNonexistent( null, null, $this->getBatchSize(), $dfnChunkSize );
                } else {
-                       $this->deleteLinksFromNonexistent( $start, $end, $this->mBatchSize, $dfnChunkSize );
+                       $this->deleteLinksFromNonexistent( $start, $end, $this->getBatchSize(), $dfnChunkSize );
                }
        }
 
@@ -456,7 +456,7 @@ class RefreshLinks extends Maintenance {
                                __METHOD__,
                                [
                                        'ORDER BY' => [ 'cl_timestamp', 'cl_from' ],
-                                       'LIMIT' => $this->mBatchSize,
+                                       'LIMIT' => $this->getBatchSize(),
                                ]
                        );
 
@@ -470,7 +470,7 @@ class RefreshLinks extends Maintenance {
                                self::fixLinksFromArticle( $row->page_id );
                        }
 
-               } while ( $res->numRows() == $this->mBatchSize );
+               } while ( $res->numRows() == $this->getBatchSize() );
        }
 
        /**
index 2f3fc36..334ed27 100644 (file)
@@ -41,6 +41,7 @@ class UpdateRestrictions extends Maintenance {
 
        public function execute() {
                $db = $this->getDB( DB_MASTER );
+               $batchSize = $this->getBatchSize();
                if ( !$db->tableExists( 'page_restrictions' ) ) {
                        $this->error( "page_restrictions table does not exist", true );
                }
@@ -52,9 +53,9 @@ class UpdateRestrictions extends Maintenance {
                $end = $db->selectField( 'page', 'MAX(page_id)', false, __METHOD__ );
 
                # Do remaining chunk
-               $end += $this->mBatchSize - 1;
+               $end += $batchSize - 1;
                $blockStart = $start;
-               $blockEnd = $start + $this->mBatchSize - 1;
+               $blockEnd = $start + $batchSize - 1;
                $encodedExpiry = 'infinity';
                while ( $blockEnd <= $end ) {
                        $this->output( "...doing page_id from $blockStart to $blockEnd out of $end\n" );
@@ -105,8 +106,8 @@ class UpdateRestrictions extends Maintenance {
                                        throw new MWException( "Deadlock loop failed wtf :(" );
                                }
                        }
-                       $blockStart += $this->mBatchSize - 1;
-                       $blockEnd += $this->mBatchSize - 1;
+                       $blockStart += $batchSize - 1;
+                       $blockEnd += $batchSize - 1;
                        wfWaitForSlaves();
                }
                $this->output( "...removing dead rows from page_restrictions\n" );