use slave for row estimate in updateCollation.php
authorBrian Wolff <bawolff+wn@gmail.com>
Tue, 10 May 2016 19:38:27 +0000 (15:38 -0400)
committerBrian Wolff <bawolff+wn@gmail.com>
Tue, 10 May 2016 19:38:27 +0000 (15:38 -0400)
jcrespo reported a lag spike at the very beginning of running this
script. I'm guessing that's due to counting how many rows in
categorylinks to give the progress bar. Since we only need a
rough estimate for the progress meter, make that query run on
a slave. Also add a wfWaitForSlaves() immediately after it for
good measure.

Bug: T58041
Change-Id: I3cba392f0013fcb2ef86803632e2d9b1b88b3b29

maintenance/updateCollation.php

index 6d9a616..dc9431f 100644 (file)
@@ -70,6 +70,7 @@ TEXT
                global $wgCategoryCollation;
 
                $dbw = $this->getDB( DB_MASTER );
+               $dbr = $this->getDB( DB_SLAVE );
                $force = $this->getOption( 'force' );
                $dryRun = $this->getOption( 'dry-run' );
                $verboseStats = $this->getOption( 'verbose-stats' );
@@ -110,7 +111,7 @@ TEXT
                                ];
                        }
 
-                       $count = $dbw->estimateRowCount(
+                       $count = $dbr->estimateRowCount(
                                'categorylinks',
                                '*',
                                $collationConds,
@@ -118,7 +119,7 @@ TEXT
                        );
                        // Improve estimate if feasible
                        if ( $count < 1000000 ) {
-                               $count = $dbw->selectField(
+                               $count = $dbr->selectField(
                                        'categorylinks',
                                        'COUNT(*)',
                                        $collationConds,
@@ -131,6 +132,7 @@ TEXT
                                return;
                        }
                        $this->output( "Fixing collation for $count rows.\n" );
+                       wfWaitForSlaves();
                }
                $count = 0;
                $batchCount = 0;