r98693 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98692‎ | r98693 | r98694 >
Date:17:19, 2 October 2011
Author:aaron
Status:ok
Tags:
Comment:
* Added end parameter and redid arguments as parameters.
* Set $wgReadOnly to avoid firing enotif stuff and such.
* Pushed commit() statements outside of batch loop...added begin().
* Removed wfWaitForSlaves(), which is just more overhead...nothing should be writing to the DB, the transaction is there just in case.
Modified paths:
  • /trunk/phase3/maintenance/rebuildFileCache.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/rebuildFileCache.php
@@ -26,29 +26,42 @@
2727 public function __construct() {
2828 parent::__construct();
2929 $this->mDescription = "Build file cache for content pages";
30 - $this->addArg( 'start', 'Page_id to start from', true );
31 - $this->addArg( 'overwrite', 'Refresh page cache', false );
 30+ $this->addOption( 'start', 'Page_id to start from', false, true );
 31+ $this->addOption( 'end', 'Page_id to end on', false, true );
 32+ $this->addOption( 'overwrite', 'Refresh page cache' );
3233 $this->setBatchSize( 100 );
3334 }
3435
3536 public function execute() {
36 - global $wgUseFileCache, $wgDisableCounters, $wgContentNamespaces, $wgRequestTime;
 37+ global $wgUseFileCache, $wgReadOnly, $wgContentNamespaces, $wgRequestTime;
3738 global $wgTitle, $wgOut;
3839 if ( !$wgUseFileCache ) {
3940 $this->error( "Nothing to do -- \$wgUseFileCache is disabled.", true );
4041 }
41 - $wgDisableCounters = true;
42 - $start = $this->getArg( 0, "0" );
 42+ $wgReadOnly = 'Building cache'; // avoid DB writes (like enotif/counters)
 43+
 44+ $start = $this->getOption( 'start', "0" );
4345 if ( !ctype_digit( $start ) ) {
4446 $this->error( "Invalid value for start parameter.", true );
4547 }
4648 $start = intval( $start );
47 - $overwrite = $this->hasArg( 1 ) && $this->getArg( 1 ) === 'overwrite';
 49+
 50+ $end = $this->getOption( 'end', "0" );
 51+ if ( !ctype_digit( $end ) ) {
 52+ $this->error( "Invalid value for end parameter.", true );
 53+ }
 54+ $end = intval( $end );
 55+
4856 $this->output( "Building content page file cache from page {$start}!\n" );
4957
5058 $dbr = wfGetDB( DB_SLAVE );
51 - $start = $start > 0 ? $start : $dbr->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ );
52 - $end = $dbr->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ );
 59+ $overwrite = $this->getOption( 'overwrite', false );
 60+ $start = ( $start > 0 )
 61+ ? $start
 62+ : $dbr->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ );
 63+ $end = ( $end > 0 )
 64+ ? $end
 65+ : $dbr->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ );
5366 if ( !$start ) {
5467 $this->error( "Nothing to do.", true );
5568 }
@@ -69,6 +82,8 @@
7083 "page_id BETWEEN $blockStart AND $blockEnd" ),
7184 array( 'ORDER BY' => 'page_id ASC', 'USE INDEX' => 'PRIMARY' )
7285 );
 86+
 87+ $dbw->begin(); // for any changes
7388 foreach ( $res as $row ) {
7489 $rebuilt = false;
7590 $wgRequestTime = wfTime(); # bug 22852
@@ -100,18 +115,19 @@
101116 wfRestoreWarnings();
102117 $wgUseFileCache = true;
103118 ob_end_clean(); // clear buffer
104 - if ( $rebuilt )
 119+ if ( $rebuilt ) {
105120 $this->output( "Re-cached page {$row->page_id}\n" );
106 - else
 121+ } else {
107122 $this->output( "Cached page {$row->page_id}\n" );
 123+ }
108124 } else {
109125 $this->output( "Page {$row->page_id} not cacheable\n" );
110126 }
111 - $dbw->commit(); // commit any changes
112127 }
 128+ $dbw->commit(); // commit any changes (just for sanity)
 129+
113130 $blockStart += $this->mBatchSize;
114131 $blockEnd += $this->mBatchSize;
115 - wfWaitForSlaves();
116132 }
117133 $this->output( "Done!\n" );
118134

Status & tagging log