MediaWiki master
BacklinkJobUtils.php
Go to the documentation of this file.
1<?php
8
12
76 public static function partitionBacklinkJob( Job $job, $bSize, $cSize, $opts = [] ) {
77 $class = get_class( $job );
78 $title = $job->getTitle();
79 $params = $job->getParams();
80
81 $backlinkCache = MediaWikiServices::getInstance()->getBacklinkCacheFactory()
82 ->getBacklinkCache( $title );
83 if ( isset( $params['pages'] ) || empty( $params['recursive'] ) ) {
84 // this is a leaf node
85 $ranges = [];
86 $realBSize = 0;
87 wfWarn( __METHOD__ . " called on {$job->getType()} leaf job (explosive recursion)." );
88 } elseif ( isset( $params['range'] ) ) {
89 // This is a range job to trigger the insertion of partitioned/title jobs...
90 $ranges = $params['range']['subranges'];
91 $realBSize = $params['range']['batchSize'];
92 } else {
93 // This is a base job to trigger the insertion of partitioned jobs...
94 $ranges = $backlinkCache->partition( $params['table'], $bSize );
95 $realBSize = $bSize;
96 }
97
98 $extraParams = $opts['params'] ?? [];
99
100 $jobs = [];
101 // Combine the first range (of size $bSize) backlinks into leaf jobs
102 if ( isset( $ranges[0] ) ) {
103 $start = $ranges[0][0];
104 $end = isset( $ranges[1] ) ? $ranges[1][0] - 1 : false;
105
106 $iter = $backlinkCache->getLinkPages( $params['table'], $start, $end );
107 $pageSources = iterator_to_array( $iter );
109 foreach ( array_chunk( $pageSources, $cSize ) as $pageBatch ) {
110 $pages = [];
111 foreach ( $pageBatch as $page ) {
112 $pages[$page->getId()] = [ $page->getNamespace(), $page->getDBkey() ];
113 }
114 $jobs[] = new $class(
115 $title, // maintain parent job title
116 [ 'pages' => $pages ] + $extraParams
117 );
118 }
119 }
120 // Take all of the remaining ranges and build a partition job from it
121 if ( isset( $ranges[1] ) ) {
122 $jobs[] = new $class(
123 $title, // maintain parent job title
124 [
125 'recursive' => true,
126 'table' => $params['table'],
127 'range' => [
128 'start' => $ranges[1][0],
129 'end' => $ranges[count( $ranges ) - 1][1],
130 'batchSize' => $realBSize,
131 'subranges' => array_slice( $ranges, 1 )
132 ],
133 // Track how many times the base job divided for debugging
134 'division' => isset( $params['division'] )
135 ? ( $params['division'] + 1 )
136 : 1
137 ] + $extraParams
138 );
139 }
140
141 return $jobs;
142 }
143}
144
146class_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:27
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