MediaWiki  REL1_24
BacklinkJobUtils.php
Go to the documentation of this file.
00001 <?php
00031 class BacklinkJobUtils {
00067     public static function partitionBacklinkJob( Job $job, $bSize, $cSize, $opts = array() ) {
00068         $class = get_class( $job );
00069         $title = $job->getTitle();
00070         $params = $job->getParams();
00071 
00072         if ( isset( $params['pages'] ) || empty( $params['recursive'] ) ) {
00073             $ranges = array(); // sanity; this is a leaf node
00074             wfWarn( __METHOD__ . " called on {$job->getType()} leaf job (explosive recursion)." );
00075         } elseif ( isset( $params['range'] ) ) {
00076             // This is a range job to trigger the insertion of partitioned/title jobs...
00077             $ranges = $params['range']['subranges'];
00078             $realBSize = $params['range']['batchSize'];
00079         } else {
00080             // This is a base job to trigger the insertion of partitioned jobs...
00081             $ranges = $title->getBacklinkCache()->partition( $params['table'], $bSize );
00082             $realBSize = $bSize;
00083         }
00084 
00085         $extraParams = isset( $opts['params'] ) ? $opts['params'] : array();
00086 
00087         $jobs = array();
00088         // Combine the first range (of size $bSize) backlinks into leaf jobs
00089         if ( isset( $ranges[0] ) ) {
00090             list( $start, $end ) = $ranges[0];
00091             $titles = $title->getBacklinkCache()->getLinks( $params['table'], $start, $end );
00092             foreach ( array_chunk( iterator_to_array( $titles ), $cSize ) as $titleBatch ) {
00093                 $pages = array();
00094                 foreach ( $titleBatch as $tl ) {
00095                     $pages[$tl->getArticleId()] = array( $tl->getNamespace(), $tl->getDBKey() );
00096                 }
00097                 $jobs[] = new $class(
00098                     $title, // maintain parent job title
00099                     array( 'pages' => $pages ) + $extraParams
00100                 );
00101             }
00102         }
00103         // Take all of the remaining ranges and build a partition job from it
00104         if ( isset( $ranges[1] ) ) {
00105             $jobs[] = new $class(
00106                 $title, // maintain parent job title
00107                 array(
00108                     'recursive'     => true,
00109                     'table'         => $params['table'],
00110                     'range'         => array(
00111                         'start'     => $ranges[1][0],
00112                         'end'       => $ranges[count( $ranges ) - 1][1],
00113                         'batchSize' => $realBSize,
00114                         'subranges' => array_slice( $ranges, 1 )
00115                     ),
00116                 ) + $extraParams
00117             );
00118         }
00119 
00120         return $jobs;
00121     }
00122 }