http://www.mediawiki.org/wiki/Special:Code/MediaWiki/69131

Revision: 69131
Author:   aaron
Date:     2010-07-07 04:58:55 +0000 (Wed, 07 Jul 2010)

Log Message:
-----------
* 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
    trunk/extensions/FlaggedRevs/maintenance/updateTracking.php

Modified: trunk/extensions/FlaggedRevs/maintenance/updateTracking.inc
===================================================================
--- trunk/extensions/FlaggedRevs/maintenance/updateTracking.inc 2010-07-07 
04:33:53 UTC (rev 69130)
+++ trunk/extensions/FlaggedRevs/maintenance/updateTracking.inc 2010-07-07 
04:58:55 UTC (rev 69131)
@@ -3,7 +3,7 @@
 function update_flaggedrevs( $start = null ) {
        echo "Populating and correcting flaggedrevs columns\n";
        
-       $BATCH_SIZE = 500;
+       $BATCH_SIZE = 1000;
        
        $db = wfGetDB( DB_MASTER );
        
@@ -28,7 +28,9 @@
                $res = $db->select( array('revision','flaggedrevs','page'),
                        
array('fr_rev_id','fr_tags','fr_quality','page_namespace','page_title',
                                
'fr_img_name','fr_img_timestamp','fr_img_sha1','rev_page'), 
-                       $cond, __FUNCTION__ );
+                       $cond, __FUNCTION__
+               );
+               $db->begin();
                # Go through and clean up missing items, as well as correct 
fr_quality...
                foreach( $res as $row ) {
                        $tags = FlaggedRevision::expandRevisionTags( 
$row->fr_tags );
@@ -70,20 +72,20 @@
                                || $sha1 != $row->fr_img_sha1
                                || $time != $row->fr_img_timestamp )
                        {
+                               # Update the row...
+                               $db->update( 'flaggedrevs',
+                                       array( 'fr_quality' => $quality,
+                                               'fr_img_name' => $file,
+                                               'fr_img_sha1' => $sha1,
+                                               'fr_img_timestamp' => $time ),
+                                       array( 'fr_rev_id' => $row->fr_rev_id, 
'fr_page_id' => $row->rev_page ),
+                                       __FUNCTION__
+                               );
                                $changed++;
                        }
-                       # Update the row...
-                       $db->begin();
-                       $db->update( 'flaggedrevs',
-                               array( 'fr_quality' => $quality,
-                                       'fr_img_name' => $file,
-                                       'fr_img_sha1' => $sha1,
-                                       'fr_img_timestamp' => $time ),
-                               array( 'fr_rev_id' => $row->fr_rev_id, 
'fr_page_id' => $row->rev_page ),
-                               __FUNCTION__ );
-                       $db->commit();
                        $count++;
                }
+               $db->commit();
                $db->freeResult( $res );
                $blockStart += $BATCH_SIZE;
                $blockEnd += $BATCH_SIZE;
@@ -99,7 +101,9 @@
        
        $db = wfGetDB( DB_MASTER );
        
-       $start = $start ? $start : $db->selectField( 'page', 'MIN(page_id)', 
false, __FUNCTION__ );
+       if( $start === null ) {
+               $start = $db->selectField( 'page', 'MIN(page_id)', false, 
__FUNCTION__ );
+       }
        $end = $db->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ );
        if( is_null( $start ) || is_null( $end ) ){
                echo "...flaggedpages table seems to be empty.\n";
@@ -138,8 +142,9 @@
                        # Correct page_latest if needed (import/files made 
plenty of bad rows)
                        if( $revRow ) {
                                $revision = new Revision( $revRow );
-                               if( $article->updateIfNewerOn( $db, $revision ) 
)
+                               if( $article->updateIfNewerOn( $db, $revision ) 
) {
                                        $fixed++;
+                               }
                        }
                        $count++;
                }
@@ -161,107 +166,3 @@
        }
        echo "flaggedpage columns update complete ... {$count} rows [{$fixed} 
fixed] [{$deleted} deleted]\n";
 }
-
-function update_flaggedtemplates( $start = null ) {
-       echo "Removing unreferenced flaggedtemplates columns\n";
-       
-       $BATCH_SIZE = 500;
-       
-       $db = wfGetDB( DB_MASTER );
-       
-       if( $start === null ) {
-               $start = $db->selectField( 'flaggedtemplates', 
'MIN(ft_rev_id)', false, __FUNCTION__ );
-       }
-       $end = $db->selectField( 'flaggedtemplates', 'MAX(ft_rev_id)', false, 
__FUNCTION__ );
-       if( is_null( $start ) || is_null( $end ) ){
-               echo "...flaggedtemplates table seems to be empty.\n";
-               return;
-       }
-       # Do remaining chunk
-       $end += $BATCH_SIZE - 1;
-       $blockStart = $start;
-       $blockEnd = $start + $BATCH_SIZE - 1;
-       $count = 0;
-       $deleted = 0;
-       while( $blockEnd <= $end ) {
-               echo "...doing ft_rev_id from $blockStart to $blockEnd\n";
-               $cond = "ft_rev_id BETWEEN $blockStart AND $blockEnd";
-               $res = $db->select( 'flaggedtemplates', array('ft_rev_id'), 
$cond, __FUNCTION__ );
-               # Go through and update the de-normalized references...
-               foreach( $res as $row ) {
-                       $revision = Revision::newFromId( $row->ft_rev_id );
-                       # Replaces new fields into flaggedpages
-                       $frev = $revision
-                               ? FlaggedRevision::newFromTitle( 
$revision->getTitle(), $row->ft_rev_id )
-                               : null;
-                       # Somethings broke? Delete the row...
-                       if( !$frev ) {
-                               $db->begin();
-                               $db->delete( 'flaggedtemplates', 
-                                       array( 'ft_rev_id' => $row->ft_rev_id ),
-                                       __FUNCTION__ );
-                               if( $db->affectedRows() > 0 )
-                                       $deleted++;
-                               $db->commit();
-                       }
-                       $count++;
-               }
-               $db->freeResult( $res );
-               $blockStart += $BATCH_SIZE;
-               $blockEnd += $BATCH_SIZE;
-               wfWaitForSlaves( 5 );
-       }
-       echo "flaggedtemplates columns update complete ... {$count} rows 
[{$deleted} deleted]\n";
-}
-
-function update_flaggedimages( $start = null ) {
-       echo "Removing unreferenced flaggedimages columns\n";
-       
-       $BATCH_SIZE = 500;
-       
-       $db = wfGetDB( DB_MASTER );
-       
-       if( $start === null ) {
-               $start = $db->selectField( 'flaggedimages', 'MIN(fi_rev_id)', 
false, __FUNCTION__ );
-       }
-       $end = $db->selectField( 'flaggedimages', 'MAX(fi_rev_id)', false, 
__FUNCTION__ );
-       if( is_null( $start ) || is_null( $end ) ){
-               echo "...flaggedimages table seems to be empty.\n";
-               return;
-       }
-       # Do remaining chunk
-       $end += $BATCH_SIZE - 1;
-       $blockStart = $start;
-       $blockEnd = $start + $BATCH_SIZE - 1;
-       $count = 0;
-       $deleted = 0;
-       while( $blockEnd <= $end ) {
-               echo "...doing fi_rev_id from $blockStart to $blockEnd\n";
-               $cond = "fi_rev_id BETWEEN $blockStart AND $blockEnd";
-               $res = $db->select( 'flaggedimages', array('fi_rev_id'), $cond, 
__FUNCTION__ );
-               # Go through and update the de-normalized references...
-               foreach( $res as $row ) {
-                       $revision = Revision::newFromId( $row->fi_rev_id );
-                       # Replaces new fields into flaggedpages
-                       $frev = $revision
-                               ? FlaggedRevision::newFromTitle( 
$revision->getTitle(), $row->fi_rev_id )
-                               : null;
-                       # Somethings broke? Delete the row...
-                       if( !$frev ) {
-                               $db->begin();
-                               $db->delete( 'flaggedimages', 
-                                       array( 'fi_rev_id' => $row->fi_rev_id ),
-                                       __FUNCTION__ );
-                               if( $db->affectedRows() > 0 )
-                                       $deleted++;
-                               $db->commit();
-                       }
-                       $count++;
-               }
-               $db->freeResult( $res );
-               $blockStart += $BATCH_SIZE;
-               $blockEnd += $BATCH_SIZE;
-               wfWaitForSlaves( 5 );
-       }
-       echo "flaggedtemplates columns update complete ... {$count} rows 
[{$deleted} deleted]\n";
-}

Modified: trunk/extensions/FlaggedRevs/maintenance/updateTracking.php
===================================================================
--- trunk/extensions/FlaggedRevs/maintenance/updateTracking.php 2010-07-07 
04:33:53 UTC (rev 69130)
+++ trunk/extensions/FlaggedRevs/maintenance/updateTracking.php 2010-07-07 
04:58:55 UTC (rev 69131)
@@ -6,22 +6,23 @@
     $IP = dirname(__FILE__).'/../../..';
 }
 
-$options = array( 'updateonly', 'help', 'start' );
+$options = array( 'updateonly', 'help', 'startrev', 'startpage' );
 require "$IP/maintenance/commandLine.inc";
 require dirname(__FILE__) . '/updateTracking.inc';
 
-if( isset($options['help']) ) {
+if ( isset($options['help']) ) {
        echo <<<TEXT
 Purpose:
-       Correct the data in the flaggedrevs tracking tables and
-       remove any extraneous template/file inclusion data.
+       Correct the page data in the flaggedrevs tracking tables.
+       Update the quality tier of revisions based on their rating tags.
+       Migrate flagged revision file version data to proper table.
 Usage:
     php updateLinks.php --help
-    php updateLinks.php [--start <ID> | --updateonly <CALL> ]
+    php updateLinks.php [--startpage <ID> | --startrev <ID> | --updateonly 
<CALL> ]
 
     --help             : This help message
-    --<ID>             : The ID of the starting rev
-       --<CALL>           : One of revs,pages,templates, or images
+    --<ID>             : The ID of the starting rev/page
+    --<CALL>           : One of (revs, pages)
 
 TEXT;
        exit(0);
@@ -29,20 +30,27 @@
 
 error_reporting( E_ALL );
 
-$start = isset($options['start']) ? $options['start'] : null;
-$updateonly = isset($options['updateonly']) ? $options['updateonly'] : null;
+$startPage = isset( $options['startpage'] ) ?
+       (int)$options['startpage'] : null;
+$startRev = isset( $options['startrev'] ) ?
+       (int)$options['startrev'] : null;
+$updateonly = isset( $options['updateonly'] ) ?
+       $options['updateonly'] : null;
 
-$actions = array( 'revs', 'pages', 'templates', 'images' );
-if( $updateonly && in_array($updateonly,$actions) ) {
-       $do = "update_flagged{$updateonly}";
-       $do($start);
-       exit(0);
+if ( $updateonly ) {
+       switch ( $updateonly ) {
+               case 'revs':
+                       update_flaggedrevs( $startRev );
+                       break;
+               case 'pages':
+                       update_flaggedpages( $startPage );
+                       break;
+               default:
+                       echo "Invalidate operation specified.\n";
+       }
+       exit( 0 );
 }
 
-update_flaggedrevs($start);
+update_flaggedrevs( $startRev );
 
-update_flaggedpages();
-
-update_flaggedtemplates($start);
-
-update_flaggedimages($start);
+update_flaggedpages( $startPage );



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to