MediaWiki  master
BacklinkJobUtils.php
Go to the documentation of this file.
1 <?php
87  public static function partitionBacklinkJob( Job $job, $bSize, $cSize, $opts = [] ) {
88  $class = get_class( $job );
89  $title = $job->getTitle();
90  $params = $job->getParams();
91 
92  if ( isset( $params['pages'] ) || empty( $params['recursive'] ) ) {
93  $ranges = []; // sanity; this is a leaf node
94  $realBSize = 0;
95  wfWarn( __METHOD__ . " called on {$job->getType()} leaf job (explosive recursion)." );
96  } elseif ( isset( $params['range'] ) ) {
97  // This is a range job to trigger the insertion of partitioned/title jobs...
98  $ranges = $params['range']['subranges'];
99  $realBSize = $params['range']['batchSize'];
100  } else {
101  // This is a base job to trigger the insertion of partitioned jobs...
102  // @phan-suppress-next-line SecurityCheck-SQLInjection False positive T268905
103  $ranges = $title->getBacklinkCache()->partition( $params['table'], $bSize );
104  $realBSize = $bSize;
105  }
106 
107  $extraParams = $opts['params'] ?? [];
108 
109  $jobs = [];
110  // Combine the first range (of size $bSize) backlinks into leaf jobs
111  if ( isset( $ranges[0] ) ) {
112  list( $start, $end ) = $ranges[0];
113  // @phan-suppress-next-line SecurityCheck-SQLInjection False positive T268905
114  $iter = $title->getBacklinkCache()->getLinks( $params['table'], $start, $end );
115  $titles = iterator_to_array( $iter );
117  foreach ( array_chunk( $titles, $cSize ) as $titleBatch ) {
118  $pages = [];
119  foreach ( $titleBatch as $tl ) {
120  $pages[$tl->getArticleID()] = [ $tl->getNamespace(), $tl->getDBkey() ];
121  }
122  $jobs[] = new $class(
123  $title, // maintain parent job title
124  [ 'pages' => $pages ] + $extraParams
125  );
126  }
127  }
128  // Take all of the remaining ranges and build a partition job from it
129  if ( isset( $ranges[1] ) ) {
130  $jobs[] = new $class(
131  $title, // maintain parent job title
132  [
133  'recursive' => true,
134  'table' => $params['table'],
135  'range' => [
136  'start' => $ranges[1][0],
137  'end' => $ranges[count( $ranges ) - 1][1],
138  'batchSize' => $realBSize,
139  'subranges' => array_slice( $ranges, 1 )
140  ],
141  // Track how many times the base job divided for debugging
142  'division' => isset( $params['division'] )
143  ? ( $params['division'] + 1 )
144  : 1
145  ] + $extraParams
146  );
147  }
148 
149  return $jobs;
150  }
151 }
BacklinkJobUtils\partitionBacklinkJob
static partitionBacklinkJob(Job $job, $bSize, $cSize, $opts=[])
Break down $job into approximately ($bSize/$cSize) leaf jobs and a single partition job that covers t...
Definition: BacklinkJobUtils.php:87
Job
Class to both describe a background job and handle jobs.
Definition: Job.php:35
$title
$title
Definition: testCompression.php:38
BacklinkJobUtils
Class with Backlink related Job helper methods.
Definition: BacklinkJobUtils.php:51
Title
Represents a title within MediaWiki.
Definition: Title.php:46
$job
if(count( $args)< 1) $job
Definition: recompressTracked.php:50
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
Definition: GlobalFunctions.php:1080