Use unbuffered queries in cleanupTable maintenance scripts. Prevents OOM issues.
authorAndrew Garrett <werdna@users.mediawiki.org>
Mon, 21 Sep 2009 16:15:07 +0000 (16:15 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Mon, 21 Sep 2009 16:15:07 +0000 (16:15 +0000)
maintenance/cleanupTable.inc

index 80be055..ef5bebd 100644 (file)
@@ -87,6 +87,10 @@ abstract class TableCleanup extends Maintenance {
 
        protected function runTable( $table, $where, $callback ) {
                $dbw = wfGetDB( DB_MASTER );
+               
+               // Unbuffered queries, avoids OOM
+               $dbw->bufferResults( false );
+               
                $count = $dbw->selectField( $table, 'count(*)', '', __METHOD__ );
                $this->init( $count, $table );
                $this->output( "Processing $table..." );
@@ -98,8 +102,12 @@ abstract class TableCleanup extends Maintenance {
                foreach( $result as $row ) {
                        call_user_func( $callback, $row );
                }
+               
                $this->output( "Finished $table... $this->updated of $this->processed rows updated\n" );
+               
                $result->free();
+               
+               $dbw->bufferResults( true );
        }
 
        protected function hexChar( $matches ) {