r69131 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69130‎ | r69131 | r69132 >
Date:04:58, 7 July 2010
Author:aaron
Status:ok
Tags:
Comment:
* Removed update_flaggedimages/update_flaggedtemplates. Of limited use and broken for deleted revs.
* Improved rev/page start params.
* Script performance tweaks.
* Improved description.
Modified paths:
  • /trunk/extensions/FlaggedRevs/maintenance/updateTracking.inc (modified) (history)
  • /trunk/extensions/FlaggedRevs/maintenance/updateTracking.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/maintenance/updateTracking.php
@@ -6,22 +6,23 @@
77 $IP = dirname(__FILE__).'/../../..';
88 }
99
10 -$options = array( 'updateonly', 'help', 'start' );
 10+$options = array( 'updateonly', 'help', 'startrev', 'startpage' );
1111 require "$IP/maintenance/commandLine.inc";
1212 require dirname(__FILE__) . '/updateTracking.inc';
1313
14 -if( isset($options['help']) ) {
 14+if ( isset($options['help']) ) {
1515 echo <<<TEXT
1616 Purpose:
17 - Correct the data in the flaggedrevs tracking tables and
18 - remove any extraneous template/file inclusion data.
 17+ Correct the page data in the flaggedrevs tracking tables.
 18+ Update the quality tier of revisions based on their rating tags.
 19+ Migrate flagged revision file version data to proper table.
1920 Usage:
2021 php updateLinks.php --help
21 - php updateLinks.php [--start <ID> | --updateonly <CALL> ]
 22+ php updateLinks.php [--startpage <ID> | --startrev <ID> | --updateonly <CALL> ]
2223
2324 --help : This help message
24 - --<ID> : The ID of the starting rev
25 - --<CALL> : One of revs,pages,templates, or images
 25+ --<ID> : The ID of the starting rev/page
 26+ --<CALL> : One of (revs, pages)
2627
2728 TEXT;
2829 exit(0);
@@ -29,20 +30,27 @@
3031
3132 error_reporting( E_ALL );
3233
33 -$start = isset($options['start']) ? $options['start'] : null;
34 -$updateonly = isset($options['updateonly']) ? $options['updateonly'] : null;
 34+$startPage = isset( $options['startpage'] ) ?
 35+ (int)$options['startpage'] : null;
 36+$startRev = isset( $options['startrev'] ) ?
 37+ (int)$options['startrev'] : null;
 38+$updateonly = isset( $options['updateonly'] ) ?
 39+ $options['updateonly'] : null;
3540
36 -$actions = array( 'revs', 'pages', 'templates', 'images' );
37 -if( $updateonly && in_array($updateonly,$actions) ) {
38 - $do = "update_flagged{$updateonly}";
39 - $do($start);
40 - exit(0);
 41+if ( $updateonly ) {
 42+ switch ( $updateonly ) {
 43+ case 'revs':
 44+ update_flaggedrevs( $startRev );
 45+ break;
 46+ case 'pages':
 47+ update_flaggedpages( $startPage );
 48+ break;
 49+ default:
 50+ echo "Invalidate operation specified.\n";
 51+ }
 52+ exit( 0 );
4153 }
4254
43 -update_flaggedrevs($start);
 55+update_flaggedrevs( $startRev );
4456
45 -update_flaggedpages();
46 -
47 -update_flaggedtemplates($start);
48 -
49 -update_flaggedimages($start);
 57+update_flaggedpages( $startPage );
Index: trunk/extensions/FlaggedRevs/maintenance/updateTracking.inc
@@ -3,7 +3,7 @@
44 function update_flaggedrevs( $start = null ) {
55 echo "Populating and correcting flaggedrevs columns\n";
66
7 - $BATCH_SIZE = 500;
 7+ $BATCH_SIZE = 1000;
88
99 $db = wfGetDB( DB_MASTER );
1010
@@ -28,7 +28,9 @@
2929 $res = $db->select( array('revision','flaggedrevs','page'),
3030 array('fr_rev_id','fr_tags','fr_quality','page_namespace','page_title',
3131 'fr_img_name','fr_img_timestamp','fr_img_sha1','rev_page'),
32 - $cond, __FUNCTION__ );
 32+ $cond, __FUNCTION__
 33+ );
 34+ $db->begin();
3335 # Go through and clean up missing items, as well as correct fr_quality...
3436 foreach( $res as $row ) {
3537 $tags = FlaggedRevision::expandRevisionTags( $row->fr_tags );
@@ -70,20 +72,20 @@
7173 || $sha1 != $row->fr_img_sha1
7274 || $time != $row->fr_img_timestamp )
7375 {
 76+ # Update the row...
 77+ $db->update( 'flaggedrevs',
 78+ array( 'fr_quality' => $quality,
 79+ 'fr_img_name' => $file,
 80+ 'fr_img_sha1' => $sha1,
 81+ 'fr_img_timestamp' => $time ),
 82+ array( 'fr_rev_id' => $row->fr_rev_id, 'fr_page_id' => $row->rev_page ),
 83+ __FUNCTION__
 84+ );
7485 $changed++;
7586 }
76 - # Update the row...
77 - $db->begin();
78 - $db->update( 'flaggedrevs',
79 - array( 'fr_quality' => $quality,
80 - 'fr_img_name' => $file,
81 - 'fr_img_sha1' => $sha1,
82 - 'fr_img_timestamp' => $time ),
83 - array( 'fr_rev_id' => $row->fr_rev_id, 'fr_page_id' => $row->rev_page ),
84 - __FUNCTION__ );
85 - $db->commit();
8687 $count++;
8788 }
 89+ $db->commit();
8890 $db->freeResult( $res );
8991 $blockStart += $BATCH_SIZE;
9092 $blockEnd += $BATCH_SIZE;
@@ -99,7 +101,9 @@
100102
101103 $db = wfGetDB( DB_MASTER );
102104
103 - $start = $start ? $start : $db->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ );
 105+ if( $start === null ) {
 106+ $start = $db->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ );
 107+ }
104108 $end = $db->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ );
105109 if( is_null( $start ) || is_null( $end ) ){
106110 echo "...flaggedpages table seems to be empty.\n";
@@ -138,8 +142,9 @@
139143 # Correct page_latest if needed (import/files made plenty of bad rows)
140144 if( $revRow ) {
141145 $revision = new Revision( $revRow );
142 - if( $article->updateIfNewerOn( $db, $revision ) )
 146+ if( $article->updateIfNewerOn( $db, $revision ) ) {
143147 $fixed++;
 148+ }
144149 }
145150 $count++;
146151 }
@@ -161,107 +166,3 @@
162167 }
163168 echo "flaggedpage columns update complete ... {$count} rows [{$fixed} fixed] [{$deleted} deleted]\n";
164169 }
165 -
166 -function update_flaggedtemplates( $start = null ) {
167 - echo "Removing unreferenced flaggedtemplates columns\n";
168 -
169 - $BATCH_SIZE = 500;
170 -
171 - $db = wfGetDB( DB_MASTER );
172 -
173 - if( $start === null ) {
174 - $start = $db->selectField( 'flaggedtemplates', 'MIN(ft_rev_id)', false, __FUNCTION__ );
175 - }
176 - $end = $db->selectField( 'flaggedtemplates', 'MAX(ft_rev_id)', false, __FUNCTION__ );
177 - if( is_null( $start ) || is_null( $end ) ){
178 - echo "...flaggedtemplates table seems to be empty.\n";
179 - return;
180 - }
181 - # Do remaining chunk
182 - $end += $BATCH_SIZE - 1;
183 - $blockStart = $start;
184 - $blockEnd = $start + $BATCH_SIZE - 1;
185 - $count = 0;
186 - $deleted = 0;
187 - while( $blockEnd <= $end ) {
188 - echo "...doing ft_rev_id from $blockStart to $blockEnd\n";
189 - $cond = "ft_rev_id BETWEEN $blockStart AND $blockEnd";
190 - $res = $db->select( 'flaggedtemplates', array('ft_rev_id'), $cond, __FUNCTION__ );
191 - # Go through and update the de-normalized references...
192 - foreach( $res as $row ) {
193 - $revision = Revision::newFromId( $row->ft_rev_id );
194 - # Replaces new fields into flaggedpages
195 - $frev = $revision
196 - ? FlaggedRevision::newFromTitle( $revision->getTitle(), $row->ft_rev_id )
197 - : null;
198 - # Somethings broke? Delete the row...
199 - if( !$frev ) {
200 - $db->begin();
201 - $db->delete( 'flaggedtemplates',
202 - array( 'ft_rev_id' => $row->ft_rev_id ),
203 - __FUNCTION__ );
204 - if( $db->affectedRows() > 0 )
205 - $deleted++;
206 - $db->commit();
207 - }
208 - $count++;
209 - }
210 - $db->freeResult( $res );
211 - $blockStart += $BATCH_SIZE;
212 - $blockEnd += $BATCH_SIZE;
213 - wfWaitForSlaves( 5 );
214 - }
215 - echo "flaggedtemplates columns update complete ... {$count} rows [{$deleted} deleted]\n";
216 -}
217 -
218 -function update_flaggedimages( $start = null ) {
219 - echo "Removing unreferenced flaggedimages columns\n";
220 -
221 - $BATCH_SIZE = 500;
222 -
223 - $db = wfGetDB( DB_MASTER );
224 -
225 - if( $start === null ) {
226 - $start = $db->selectField( 'flaggedimages', 'MIN(fi_rev_id)', false, __FUNCTION__ );
227 - }
228 - $end = $db->selectField( 'flaggedimages', 'MAX(fi_rev_id)', false, __FUNCTION__ );
229 - if( is_null( $start ) || is_null( $end ) ){
230 - echo "...flaggedimages table seems to be empty.\n";
231 - return;
232 - }
233 - # Do remaining chunk
234 - $end += $BATCH_SIZE - 1;
235 - $blockStart = $start;
236 - $blockEnd = $start + $BATCH_SIZE - 1;
237 - $count = 0;
238 - $deleted = 0;
239 - while( $blockEnd <= $end ) {
240 - echo "...doing fi_rev_id from $blockStart to $blockEnd\n";
241 - $cond = "fi_rev_id BETWEEN $blockStart AND $blockEnd";
242 - $res = $db->select( 'flaggedimages', array('fi_rev_id'), $cond, __FUNCTION__ );
243 - # Go through and update the de-normalized references...
244 - foreach( $res as $row ) {
245 - $revision = Revision::newFromId( $row->fi_rev_id );
246 - # Replaces new fields into flaggedpages
247 - $frev = $revision
248 - ? FlaggedRevision::newFromTitle( $revision->getTitle(), $row->fi_rev_id )
249 - : null;
250 - # Somethings broke? Delete the row...
251 - if( !$frev ) {
252 - $db->begin();
253 - $db->delete( 'flaggedimages',
254 - array( 'fi_rev_id' => $row->fi_rev_id ),
255 - __FUNCTION__ );
256 - if( $db->affectedRows() > 0 )
257 - $deleted++;
258 - $db->commit();
259 - }
260 - $count++;
261 - }
262 - $db->freeResult( $res );
263 - $blockStart += $BATCH_SIZE;
264 - $blockEnd += $BATCH_SIZE;
265 - wfWaitForSlaves( 5 );
266 - }
267 - echo "flaggedtemplates columns update complete ... {$count} rows [{$deleted} deleted]\n";
268 -}

Status & tagging log