Don't log HttpErrors in the exception log, use MWLogger
[lhc/web/wiklou.git] / maintenance / refreshLinks.php
index eca207a..b2f7497 100644 (file)
@@ -65,7 +65,8 @@ class RefreshLinks extends Maintenance {
         * @param bool $oldRedirectsOnly Only fix redirects without redirect entries
         */
        private function doRefreshLinks( $start, $newOnly = false, $maxLag = false,
-                                               $end = 0, $redirectsOnly = false, $oldRedirectsOnly = false ) {
+               $end = 0, $redirectsOnly = false, $oldRedirectsOnly = false
+       ) {
                global $wgParser, $wgUseTidy;
 
                $reportingInterval = 100;
@@ -196,6 +197,7 @@ class RefreshLinks extends Maintenance {
                        // Delete any redirect table entry for it
                        $dbw->delete( 'redirect', array( 'rd_from' => $id ),
                                __METHOD__ );
+
                        return;
                }
 
@@ -260,10 +262,7 @@ class RefreshLinks extends Maintenance {
                wfWaitForSlaves();
 
                $dbw = wfGetDB( DB_MASTER );
-
-               $lb = wfGetLBFactory()->newMainLB();
-               $dbr = $lb->getConnection( DB_SLAVE );
-               $dbr->bufferResults( false );
+               $dbr = wfGetDB( DB_SLAVE );
 
                $linksTables = array( // table name => page_id field
                        'pagelinks' => 'pl_from',
@@ -280,38 +279,36 @@ class RefreshLinks extends Maintenance {
                foreach ( $linksTables as $table => $field ) {
                        $this->output( "Retrieving illegal entries from $table... " );
 
-                       // SELECT DISTINCT( $field ) FROM $table LEFT JOIN page ON $field=page_id WHERE page_id IS NULL;
-                       $results = $dbr->select(
-                               array( $table, 'page' ),
-                               $field,
-                               array( 'page_id' => null ),
-                               __METHOD__,
-                               'DISTINCT',
-                               array( 'page' => array( 'LEFT JOIN', "$field=page_id" ) )
-                       );
-
+                       $start = 0;
                        $counter = 0;
-                       $list = array();
                        $this->output( "0.." );
-                       foreach ( $results as $row ) {
-                               $counter++;
-                               $list[] = $row->$field;
-                               if ( ( $counter % $batchSize ) == 0 ) {
-                                       wfWaitForSlaves();
-                                       $dbw->delete( $table, array( $field => $list ), __METHOD__ );
 
+                       do {
+                               $ids = $dbr->selectFieldValues(
+                                       $table,
+                                       $field,
+                                       array(
+                                               "$field >= {$dbr->addQuotes( $start )}",
+                                               "$field NOT IN ({$dbr->selectSQLText( 'page', 'page_id' )})",
+                                       ),
+                                       __METHOD__,
+                                       array( 'DISTINCT', 'ORDER BY' => $field, 'LIMIT' => $batchSize )
+                               );
+
+                               $numIds = count( $ids );
+                               if ( $numIds ) {
+                                       $counter += $numIds;
+                                       wfWaitForSlaves();
+                                       $dbw->delete( $table, array( $field => $ids ), __METHOD__ );
                                        $this->output( $counter . ".." );
-                                       $list = array();
+                                       $start = $ids[$numIds - 1] + 1;
                                }
-                       }
-                       $this->output( $counter );
-                       if ( count( $list ) > 0 ) {
-                               $dbw->delete( $table, array( $field => $list ), __METHOD__ );
-                       }
+
+                       } while ( $numIds >= $batchSize );
+
                        $this->output( "\n" );
                        wfWaitForSlaves();
                }
-               $lb->closeAll();
        }
 }