r62509 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62508‎ | r62509 | r62510 >
Date:10:20, 15 February 2010
Author:happydog
Status:resolved (Comments)
Tags:
Comment:
CodeReview: Added a new 'precache' argument to svnImport.php. If omitted it defaults to the previous hard-coded value of 50. Can be used to increase or decrease the number of revisions to pre-cache, but more usefully can be set to 0 to skip pre-caching or -1 to pre-cache all revisions (useful when adding a repository to MW).

I also amended the SQL (now on line 97) so that it skips rows that have already had the diff filled in.
Modified paths:
  • /trunk/extensions/CodeReview/svnImport.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/svnImport.php
@@ -1,5 +1,7 @@
22 <?php
33
 4+$optionsWithArgs = array( 'precache' );
 5+
46 $IP = getenv( 'MW_INSTALL_PATH' );
57 if ( $IP === false )
68 $IP = dirname( __FILE__ ) . '/../..';
@@ -10,6 +12,14 @@
1113 die;
1214 }
1315
 16+$cacheSize = 50;
 17+if ( isset( $options['precache'] ) ) {
 18+ if ( is_numeric( $options['precache'] ) && $options['precache'] >= -1 )
 19+ $cacheSize = intval( $options['precache'] );
 20+ else
 21+ die( "Invalid argument for --precache (must be a positive integer, or -1 for all)" );
 22+}
 23+
1424 $repo = CodeRepository::newFromName( $args[0] );
1525
1626 if ( !$repo ) {
@@ -70,16 +80,31 @@
7181 wfWaitForSlaves( 5 );
7282 }
7383
74 -echo "Pre-caching the latest 50 diffs...\n";
75 -$dbw = wfGetDB( DB_MASTER );
76 -$res = $dbw->select( 'code_rev', 'cr_id',
77 - array( 'cr_repo_id' => $repo->getId() ),
78 - __METHOD__,
79 - array( 'ORDER BY' => 'cr_id DESC', 'LIMIT' => 50 )
80 -);
81 -while ( $row = $dbw->fetchObject( $res ) ) {
82 - $rev = $repo->getRevision( $row->cr_id );
83 - $diff = $repo->getDiff( $row->cr_id ); // trigger caching
84 - echo "Diff r{$row->cr_id} done\n";
 84+if ( $cacheSize != 0 ) {
 85+ if ( $cacheSize == -1 )
 86+ echo "Pre-caching all uncached diffs...\n";
 87+ elseif ( $cacheSize == 1 )
 88+ echo "Pre-caching the latest diff...\n";
 89+ else
 90+ echo "Pre-caching the latest $cacheSize diffs...\n";
 91+
 92+ $dbw = wfGetDB( DB_MASTER );
 93+ $options = array( 'ORDER BY' => 'cr_id DESC' );
 94+ if ( $cacheSize > 0 )
 95+ $options['LIMIT'] = $cacheSize;
 96+
 97+ $res = $dbw->select( 'code_rev', 'cr_id',
 98+ array( 'cr_repo_id' => $repo->getId(), 'cr_diff IS NULL OR cr_diff = ""' ),
 99+ __METHOD__,
 100+ $options
 101+ );
 102+ while ( $row = $dbw->fetchObject( $res ) ) {
 103+ $rev = $repo->getRevision( $row->cr_id );
 104+ $diff = $repo->getDiff( $row->cr_id ); // trigger caching
 105+ echo "Diff r{$row->cr_id} done\n";
 106+ }
85107 }
 108+else
 109+ echo "Pre-caching skipped.\n";
 110+
86111 echo "Done!\n";

Follow-up revisions

RevisionCommit summaryAuthorDate
r62954CodeReview: Changed the 'precache' argument to svnImport.php so that precachi...happydog11:44, 25 February 2010

Comments

#Comment by Tim Starling (talk | contribs)   07:19, 22 February 2010

It's a weakly typed language, you don't need hacks like this. Get rid of this "-1 means all" rubbish and just use the string "all". Put braces around conditional blocks.

#Comment by HappyDog (talk | contribs)   11:58, 25 February 2010

Braces were fixed by demon in his big rewrite (r62914). I fixed the 'all' issue in r62954.

Status & tagging log