MediaWiki master
BacklinkJobUtils.php
Go to the documentation of this file.
1<?php
22
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 $start = $ranges[0][0];
118 $end = isset( $ranges[1] ) ? $ranges[1][0] - 1 : false;
119
120 $iter = $backlinkCache->getLinkPages( $params['table'], $start, $end );
121 $pageSources = iterator_to_array( $iter );
123 foreach ( array_chunk( $pageSources, $cSize ) as $pageBatch ) {
124 $pages = [];
125 foreach ( $pageBatch as $page ) {
126 $pages[$page->getId()] = [ $page->getNamespace(), $page->getDBkey() ];
127 }
128 $jobs[] = new $class(
129 $title, // maintain parent job title
130 [ 'pages' => $pages ] + $extraParams
131 );
132 }
133 }
134 // Take all of the remaining ranges and build a partition job from it
135 if ( isset( $ranges[1] ) ) {
136 $jobs[] = new $class(
137 $title, // maintain parent job title
138 [
139 'recursive' => true,
140 'table' => $params['table'],
141 'range' => [
142 'start' => $ranges[1][0],
143 'end' => $ranges[count( $ranges ) - 1][1],
144 'batchSize' => $realBSize,
145 'subranges' => array_slice( $ranges, 1 )
146 ],
147 // Track how many times the base job divided for debugging
148 'division' => isset( $params['division'] )
149 ? ( $params['division'] + 1 )
150 : 1
151 ] + $extraParams
152 );
153 }
154
155 return $jobs;
156 }
157}
158
160class_alias( BacklinkJobUtils::class, 'BacklinkJobUtils' );
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
Describe and execute a background job.
Definition Job.php:41
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...
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Interface for objects (potentially) representing an editable wiki page.
if(count( $args)< 1) $job