MediaWiki REL1_39
BacklinkJobUtils.php
Go to the documentation of this file.
1<?php
26
90 public static function partitionBacklinkJob( Job $job, $bSize, $cSize, $opts = [] ) {
91 $class = get_class( $job );
92 $title = $job->getTitle();
93 $params = $job->getParams();
94
95 $backlinkCache = MediaWikiServices::getInstance()->getBacklinkCacheFactory()
96 ->getBacklinkCache( $title );
97 if ( isset( $params['pages'] ) || empty( $params['recursive'] ) ) {
98 // this is a leaf node
99 $ranges = [];
100 $realBSize = 0;
101 wfWarn( __METHOD__ . " called on {$job->getType()} leaf job (explosive recursion)." );
102 } elseif ( isset( $params['range'] ) ) {
103 // This is a range job to trigger the insertion of partitioned/title jobs...
104 $ranges = $params['range']['subranges'];
105 $realBSize = $params['range']['batchSize'];
106 } else {
107 // This is a base job to trigger the insertion of partitioned jobs...
108 $ranges = $backlinkCache->partition( $params['table'], $bSize );
109 $realBSize = $bSize;
110 }
111
112 $extraParams = $opts['params'] ?? [];
113
114 $jobs = [];
115 // Combine the first range (of size $bSize) backlinks into leaf jobs
116 if ( isset( $ranges[0] ) ) {
117 list( $start, $end ) = $ranges[0];
118
119 $iter = $backlinkCache->getLinkPages( $params['table'], $start, $end );
120 $pageSources = iterator_to_array( $iter );
122 foreach ( array_chunk( $pageSources, $cSize ) as $pageBatch ) {
123 $pages = [];
124 foreach ( $pageBatch as $page ) {
125 $pages[$page->getId()] = [ $page->getNamespace(), $page->getDBkey() ];
126 }
127 $jobs[] = new $class(
128 $title, // maintain parent job title
129 [ 'pages' => $pages ] + $extraParams
130 );
131 }
132 }
133 // Take all of the remaining ranges and build a partition job from it
134 if ( isset( $ranges[1] ) ) {
135 $jobs[] = new $class(
136 $title, // maintain parent job title
137 [
138 'recursive' => true,
139 'table' => $params['table'],
140 'range' => [
141 'start' => $ranges[1][0],
142 'end' => $ranges[count( $ranges ) - 1][1],
143 'batchSize' => $realBSize,
144 'subranges' => array_slice( $ranges, 1 )
145 ],
146 // Track how many times the base job divided for debugging
147 'division' => isset( $params['division'] )
148 ? ( $params['division'] + 1 )
149 : 1
150 ] + $extraParams
151 );
152 }
153
154 return $jobs;
155 }
156}
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:39
Service locator for MediaWiki core services.
Interface for objects (potentially) representing an editable wiki page.
if(count( $args)< 1) $job