MediaWiki master
BacklinkJobUtils.php
Go to the documentation of this file.
1<?php
23
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 $backlinkCache = MediaWikiServices::getInstance()->getBacklinkCacheFactory()
93 ->getBacklinkCache( $title );
94 if ( isset( $params['pages'] ) || empty( $params['recursive'] ) ) {
95 // this is a leaf node
96 $ranges = [];
97 $realBSize = 0;
98 wfWarn( __METHOD__ . " called on {$job->getType()} leaf job (explosive recursion)." );
99 } elseif ( isset( $params['range'] ) ) {
100 // This is a range job to trigger the insertion of partitioned/title jobs...
101 $ranges = $params['range']['subranges'];
102 $realBSize = $params['range']['batchSize'];
103 } else {
104 // This is a base job to trigger the insertion of partitioned jobs...
105 $ranges = $backlinkCache->partition( $params['table'], $bSize );
106 $realBSize = $bSize;
107 }
108
109 $extraParams = $opts['params'] ?? [];
110
111 $jobs = [];
112 // Combine the first range (of size $bSize) backlinks into leaf jobs
113 if ( isset( $ranges[0] ) ) {
114 $start = $ranges[0][0];
115 $end = isset( $ranges[1] ) ? $ranges[1][0] - 1 : false;
116
117 $iter = $backlinkCache->getLinkPages( $params['table'], $start, $end );
118 $pageSources = iterator_to_array( $iter );
120 foreach ( array_chunk( $pageSources, $cSize ) as $pageBatch ) {
121 $pages = [];
122 foreach ( $pageBatch as $page ) {
123 $pages[$page->getId()] = [ $page->getNamespace(), $page->getDBkey() ];
124 }
125 $jobs[] = new $class(
126 $title, // maintain parent job title
127 [ 'pages' => $pages ] + $extraParams
128 );
129 }
130 }
131 // Take all of the remaining ranges and build a partition job from it
132 if ( isset( $ranges[1] ) ) {
133 $jobs[] = new $class(
134 $title, // maintain parent job title
135 [
136 'recursive' => true,
137 'table' => $params['table'],
138 'range' => [
139 'start' => $ranges[1][0],
140 'end' => $ranges[count( $ranges ) - 1][1],
141 'batchSize' => $realBSize,
142 'subranges' => array_slice( $ranges, 1 )
143 ],
144 // Track how many times the base job divided for debugging
145 'division' => isset( $params['division'] )
146 ? ( $params['division'] + 1 )
147 : 1
148 ] + $extraParams
149 );
150 }
151
152 return $jobs;
153 }
154}
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
array $params
The job parameters.
Helper for a Job that updates links to a given page title.
static partitionBacklinkJob(Job $job, $bSize, $cSize, $opts=[])
Break down $job into approximately ($bSize/$cSize) leaf jobs and a single partition job that covers t...
Describe and execute a background job.
Definition Job.php:41
Service locator for MediaWiki core services.
Interface for objects (potentially) representing an editable wiki page.
if(count( $args)< 1) $job