MediaWiki
master
Toggle main menu visibility
BacklinkJobUtils.php
Go to the documentation of this file.
1
<?php
6
7
namespace
MediaWiki\JobQueue\Utils
;
8
9
use
MediaWiki\JobQueue\Job
;
10
use
MediaWiki\JobQueue\Jobs\HTMLCacheUpdateJob
;
11
use
MediaWiki\JobQueue\Jobs\RefreshLinksJob
;
12
use
MediaWiki\MediaWikiServices
;
13
use
MediaWiki\Page\PageIdentity
;
14
42
class
BacklinkJobUtils
{
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
148
class_alias( BacklinkJobUtils::class,
'BacklinkJobUtils'
);
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
Definition
GlobalFunctions.php:509
MediaWiki\JobQueue\Job
Describe and execute a background job.
Definition
Job.php:28
MediaWiki\JobQueue\Jobs\HTMLCacheUpdateJob
Job to purge the HTML/file cache for all pages that link to or use another page or file.
Definition
HTMLCacheUpdateJob.php:29
MediaWiki\JobQueue\Jobs\RefreshLinksJob
Job to update link tables for rerendered wiki pages.
Definition
RefreshLinksJob.php:105
MediaWiki\JobQueue\Utils\BacklinkJobUtils
Helper for a Job that updates links to a given page title.
Definition
BacklinkJobUtils.php:42
MediaWiki\JobQueue\Utils\BacklinkJobUtils\partitionBacklinkJob
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...
Definition
BacklinkJobUtils.php:78
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
Definition
MediaWikiServices.php:273
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition
MediaWikiServices.php:361
MediaWiki\Page\PageIdentity
Interface for objects (potentially) representing an editable wiki page.
Definition
PageIdentity.php:53
MediaWiki\JobQueue\Utils
Definition
BacklinkJobUtils.php:7
$job
if(count( $args)< 1) $job
Definition
recompressTracked.php:38
includes
JobQueue
Utils
BacklinkJobUtils.php
Generated on
for MediaWiki by
1.18.0