r47334 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47333‎ | r47334 | r47335 >
Date:19:09, 16 February 2009
Author:ialex
Status:ok
Tags:
Comment:
Made WatchlistCleanup and CapsCleanup extend TableCleanup rather than FiveUpgrade so that they don't need to re-implement cleanup() and runTable()
Modified paths:
  • /trunk/phase3/maintenance/cleanupCaps.php (modified) (history)
  • /trunk/phase3/maintenance/cleanupTable.inc (modified) (history)
  • /trunk/phase3/maintenance/cleanupWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/cleanupWatchlist.php
@@ -29,82 +29,18 @@
3030 * @ingroup Maintenance
3131 */
3232
33 -$options = array( 'fix' );
34 -
3533 require_once( 'commandLine.inc' );
36 -require_once( 'FiveUpgrade.inc' );
 34+require_once( 'CleanupTable.inc' );
3735
3836 /**
3937 * @ingroup Maintenance
4038 */
41 -class WatchlistCleanup extends FiveUpgrade {
42 - function WatchlistCleanup( $dryrun = false ) {
43 - parent::FiveUpgrade();
44 -
45 - $this->maxLag = 10; # if slaves are lagged more than 10 secs, wait
46 - $this->dryrun = $dryrun;
 39+class WatchlistCleanup extends TableCleanup {
 40+ function __construct( $dryrun = false ) {
 41+ parent::__construct( 'watchlist', $dryrun );
4742 }
4843
49 - function cleanup() {
50 - $this->runTable( 'watchlist',
51 - '',
52 - array( &$this, 'processEntry' ) );
53 - }
54 -
55 - function init( $count, $table ) {
56 - $this->processed = 0;
57 - $this->updated = 0;
58 - $this->count = $count;
59 - $this->startTime = wfTime();
60 - $this->table = $table;
61 - }
62 -
63 - function progress( $updated ) {
64 - $this->updated += $updated;
65 - $this->processed++;
66 - if( $this->processed % 100 != 0 ) {
67 - return;
68 - }
69 - $portion = $this->processed / $this->count;
70 - $updateRate = $this->updated / $this->processed;
71 -
72 - $now = wfTime();
73 - $delta = $now - $this->startTime;
74 - $estimatedTotalTime = $delta / $portion;
75 - $eta = $this->startTime + $estimatedTotalTime;
76 -
77 - printf( "%s %s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
78 - wfWikiID(),
79 - wfTimestamp( TS_DB, intval( $now ) ),
80 - $portion * 100.0,
81 - $this->table,
82 - wfTimestamp( TS_DB, intval( $eta ) ),
83 - $this->processed,
84 - $this->count,
85 - $this->processed / $delta,
86 - $updateRate * 100.0 );
87 - flush();
88 - }
89 -
90 - function runTable( $table, $where, $callback ) {
91 - $fname = 'WatchlistCleanup::runTable';
92 -
93 - $count = $this->dbw->selectField( $table, 'count(*)', '', $fname );
94 - $this->init( $count, 'watchlist' );
95 - $this->log( "Processing $table..." );
96 -
97 - $tableName = $this->dbr->tableName( $table );
98 - $sql = "SELECT * FROM $tableName $where";
99 - $result = $this->dbr->query( $sql, $fname );
100 -
101 - while( $row = $this->dbr->fetchObject( $result ) ) {
102 - call_user_func( $callback, $row );
103 - }
104 - $this->log( "Finished $table... $this->updated of $this->processed rows updated" );
105 - $this->dbr->freeResult( $result );
106 - }
107 -
108 - function processEntry( $row ) {
 44+ function processPage( $row ) {
10945 $current = Title::makeTitle( $row->wl_namespace, $row->wl_title );
11046 $display = $current->getPrefixedText();
11147
@@ -122,13 +58,13 @@
12359 }
12460
12561 function removeWatch( $row ) {
126 - if( !$this->dryrun) {
 62+ if( !$this->dryrun ) {
12763 $dbw = wfGetDB( DB_MASTER );
12864 $dbw->delete( 'watchlist', array(
12965 'wl_user' => $row->wl_user,
13066 'wl_namespace' => $row->wl_namespace,
13167 'wl_title' => $row->wl_title ),
132 - 'WatchlistCleanup::removeWatch' );
 68+ __METHOD__ );
13369 $this->log( '- removed' );
13470 }
13571 }
Index: trunk/phase3/maintenance/cleanupTable.inc
@@ -61,21 +61,19 @@
6262 }
6363
6464 function runTable( $table, $where, $callback ) {
65 - $fname = 'CapsCleanup::buildTable';
66 -
67 - $count = $this->dbw->selectField( $table, 'count(*)', '', $fname );
 65+ $count = $this->dbw->selectField( $table, 'count(*)', '', __METHOD__ );
6866 $this->init( $count, $table );
6967 $this->log( "Processing $table..." );
7068
7169 $tableName = $this->dbr->tableName( $table );
7270 $sql = "SELECT * FROM $tableName $where";
73 - $result = $this->dbr->query( $sql, $fname );
 71+ $result = $this->dbr->query( $sql, __METHOD__ );
7472
75 - while( $row = $this->dbr->fetchObject( $result ) ) {
 73+ foreach( $result as $row ) {
7674 call_user_func( $callback, $row );
7775 }
7876 $this->log( "Finished $table... $this->updated of $this->processed rows updated" );
79 - $this->dbr->freeResult( $result );
 77+ $result->free();
8078 }
8179
8280 function hexChar( $matches ) {
Index: trunk/phase3/maintenance/cleanupCaps.php
@@ -29,20 +29,17 @@
3030 * @ingroup maintenance
3131 */
3232
33 -$options = array( 'dry-run' );
 33+$optionsWithArgs = array( 'namespace' );
3434
3535 require_once( 'commandLine.inc' );
36 -require_once( 'FiveUpgrade.inc' );
 36+require_once( 'CleanupTable.inc' );
3737
3838 /**
3939 * @ingroup Maintenance
4040 */
41 -class CapsCleanup extends FiveUpgrade {
42 - function CapsCleanup( $dryrun = false, $namespace=0 ) {
43 - parent::FiveUpgrade();
44 -
45 - $this->maxLag = 10; # if slaves are lagged more than 10 secs, wait
46 - $this->dryrun = $dryrun;
 41+class CapsCleanup extends TableCleanup {
 42+ function __construct( $dryrun = false, $namespace = 0 ) {
 43+ parent::__construct( 'page', $dryrun );
4744 $this->namespace = intval( $namespace );
4845 }
4946
@@ -53,62 +50,11 @@
5451 return false;
5552 }
5653
57 - $this->runTable( 'page', 'WHERE page_namespace=' . $this->namespace,
 54+ $this->runTable( $this->targetTable,
 55+ 'WHERE page_namespace=' . $this->namespace,
5856 array( &$this, 'processPage' ) );
5957 }
6058
61 - function init( $count, $table ) {
62 - $this->processed = 0;
63 - $this->updated = 0;
64 - $this->count = $count;
65 - $this->startTime = wfTime();
66 - $this->table = $table;
67 - }
68 -
69 - function progress( $updated ) {
70 - $this->updated += $updated;
71 - $this->processed++;
72 - if( $this->processed % 100 != 0 ) {
73 - return;
74 - }
75 - $portion = $this->processed / $this->count;
76 - $updateRate = $this->updated / $this->processed;
77 -
78 - $now = wfTime();
79 - $delta = $now - $this->startTime;
80 - $estimatedTotalTime = $delta / $portion;
81 - $eta = $this->startTime + $estimatedTotalTime;
82 -
83 - printf( "%s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
84 - wfTimestamp( TS_DB, intval( $now ) ),
85 - $portion * 100.0,
86 - $this->table,
87 - wfTimestamp( TS_DB, intval( $eta ) ),
88 - $this->processed,
89 - $this->count,
90 - $this->processed / $delta,
91 - $updateRate * 100.0 );
92 - flush();
93 - }
94 -
95 - function runTable( $table, $where, $callback ) {
96 - $fname = 'CapsCleanup::buildTable';
97 -
98 - $count = $this->dbw->selectField( $table, 'count(*)', '', $fname );
99 - $this->init( $count, 'page' );
100 - $this->log( "Processing $table..." );
101 -
102 - $tableName = $this->dbr->tableName( $table );
103 - $sql = "SELECT * FROM $tableName $where";
104 - $result = $this->dbr->query( $sql, $fname );
105 -
106 - while( $row = $this->dbr->fetchObject( $result ) ) {
107 - call_user_func( $callback, $row );
108 - }
109 - $this->log( "Finished $table... $this->updated of $this->processed rows updated" );
110 - $this->dbr->freeResult( $result );
111 - }
112 -
11359 function processPage( $row ) {
11460 global $wgContLang;
11561

Status & tagging log