Index: trunk/extensions/CodeReview/svnImport.php |
— | — | @@ -1,5 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
| 4 | +$optionsWithArgs = array( 'precache' ); |
| 5 | + |
4 | 6 | $IP = getenv( 'MW_INSTALL_PATH' ); |
5 | 7 | if ( $IP === false ) |
6 | 8 | $IP = dirname( __FILE__ ) . '/../..'; |
— | — | @@ -10,6 +12,14 @@ |
11 | 13 | die; |
12 | 14 | } |
13 | 15 | |
| 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 | + |
14 | 24 | $repo = CodeRepository::newFromName( $args[0] ); |
15 | 25 | |
16 | 26 | if ( !$repo ) { |
— | — | @@ -70,16 +80,31 @@ |
71 | 81 | wfWaitForSlaves( 5 ); |
72 | 82 | } |
73 | 83 | |
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 | + } |
85 | 107 | } |
| 108 | +else |
| 109 | + echo "Pre-caching skipped.\n"; |
| 110 | + |
86 | 111 | echo "Done!\n"; |