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