41 private const NORMAL_MAX_LAG = 10;
48 $this->removeDuplicates = (
54 $this->params += [
'causeAction' =>
'HTMLCacheUpdateJob',
'causeAgent' =>
'unknown' ];
65 $title = Title::castFromPageReference( $page );
73 "htmlCacheUpdate:{$table}:{$title->getPrefixedText()}"
78 public function run() {
79 $updateRowsPerJob = MediaWikiServices::getInstance()->getMainConfig()->get(
80 MainConfigNames::UpdateRowsPerJob );
81 $updateRowsPerQuery = MediaWikiServices::getInstance()->getMainConfig()->get(
82 MainConfigNames::UpdateRowsPerQuery );
83 if ( isset( $this->params[
'table'] ) && !isset( $this->params[
'pages'] ) ) {
84 $this->params[
'recursive'] =
true;
88 if ( !empty( $this->params[
'recursive'] ) ) {
92 $extraParams[
'causeAction'] = $this->params[
'causeAction'];
93 $extraParams[
'causeAgent'] = $this->params[
'causeAgent'];
101 [
'params' => $extraParams ]
103 MediaWikiServices::getInstance()->getJobQueueGroup()->push( $jobs );
105 } elseif ( isset( $this->params[
'pages'] ) ) {
111 $t->getArticleID() => [
$t->getNamespace(),
$t->getDBkey() ]
123 $pageIds = array_keys( $pages );
128 $rootTsUnix =
wfTimestampOrNull( TS_UNIX, $this->params[
'rootJobTimestamp'] ??
null );
137 $newTouchedUnix = time();
139 $casTsUnix = $rootTsUnix ?? $newTouchedUnix;
141 $services = MediaWikiServices::getInstance();
142 $config = $services->getMainConfig();
144 $lbFactory = $services->getDBLoadBalancerFactory();
145 $dbw = $lbFactory->getPrimaryDatabase();
146 $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
149 $batches = array_chunk( $pageIds, $config->get( MainConfigNames::UpdateRowsPerQuery ) );
150 foreach ( $batches as $batch ) {
151 $dbw->update(
'page',
152 [
'page_touched' => $dbw->timestamp( $newTouchedUnix ) ],
155 "page_touched < " . $dbw->addQuotes( $dbw->timestamp( $casTsUnix ) )
159 if ( count( $batches ) > 1 ) {
160 $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
164 $titleArray = TitleArray::newFromResult( $dbw->select(
167 [
'page_namespace',
'page_title' ],
168 $config->get( MainConfigNames::PageLanguageUseDB ) ? [
'page_lang' ] : []
170 [
'page_id' => $pageIds,
'page_touched' => $dbw->timestamp( $newTouchedUnix ) ],
175 $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
176 $htmlCache->purgeTitleUrls(
178 $htmlCache::PURGE_NAIVE | $htmlCache::PURGE_URLS_LINKSUPDATE_ONLY,
179 [ $htmlCache::UNLESS_CACHE_MTIME_AFTER => $casTsUnix + self::NORMAL_MAX_LAG ]
184 $info = parent::getDeduplicationInfo();
185 if ( is_array( $info[
'params'] ) ) {
188 if ( isset( $info[
'params'][
'pages'] ) ) {
189 unset( $info[
'namespace'] );
190 unset( $info[
'title'] );
198 if ( !empty( $this->params[
'recursive'] ) ) {
200 } elseif ( isset( $this->params[
'pages'] ) ) {
201 return count( $this->params[
'pages'] );
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
static partitionBacklinkJob(Job $job, $bSize, $cSize, $opts=[])
Break down $job into approximately ($bSize/$cSize) leaf jobs and a single partition job that covers t...
Job to purge the HTML/file cache for all pages that link to or use another page or file.
getDeduplicationInfo()
Subclasses may need to override this to make duplication detection work.
__construct(Title $title, array $params)
static newForBacklinks(PageReference $page, $table, $params=[])
invalidateTitles(array $pages)
Class to both describe a background job and handle jobs.
array $params
Array of job parameters.
static newRootJobParams( $key)
Get "root job" parameters for a task.
A class containing constants representing the names of configuration variables.