MediaWiki 1.42.0
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, $end ] = $ranges[0];
115
116 $iter = $backlinkCache->getLinkPages( $params['table'], $start, $end );
117 $pageSources = iterator_to_array( $iter );
119 foreach ( array_chunk( $pageSources, $cSize ) as $pageBatch ) {
120 $pages = [];
121 foreach ( $pageBatch as $page ) {
122 $pages[$page->getId()] = [ $page->getNamespace(), $page->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.
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:40
Service locator for MediaWiki core services.
Interface for objects (potentially) representing an editable wiki page.
if(count( $args)< 1) $job