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