MediaWiki  1.32.5
HTMLCacheUpdateJob.php
Go to the documentation of this file.
1 <?php
26 
38 class HTMLCacheUpdateJob extends Job {
40  parent::__construct( 'htmlCacheUpdate', $title, $params );
41  // Avoid the overhead of de-duplication when it would be pointless.
42  // Note that these jobs always set page_touched to the current time,
43  // so letting the older existing job "win" is still correct.
44  $this->removeDuplicates = (
45  // Ranges rarely will line up
46  !isset( $params['range'] ) &&
47  // Multiple pages per job make matches unlikely
48  !( isset( $params['pages'] ) && count( $params['pages'] ) != 1 )
49  );
50  $this->params += [ 'causeAction' => 'unknown', 'causeAgent' => 'unknown' ];
51  }
52 
59  public static function newForBacklinks( Title $title, $table, $params = [] ) {
60  return new self(
61  $title,
62  [
63  'table' => $table,
64  'recursive' => true
65  ] + Job::newRootJobParams( // "overall" refresh links job info
66  "htmlCacheUpdate:{$table}:{$title->getPrefixedText()}"
67  ) + $params
68  );
69  }
70 
71  function run() {
73 
74  if ( isset( $this->params['table'] ) && !isset( $this->params['pages'] ) ) {
75  $this->params['recursive'] = true; // b/c; base job
76  }
77 
78  // Job to purge all (or a range of) backlink pages for a page
79  if ( !empty( $this->params['recursive'] ) ) {
80  // Carry over information for de-duplication
81  $extraParams = $this->getRootJobParams();
82  // Carry over cause information for logging
83  $extraParams['causeAction'] = $this->params['causeAction'];
84  $extraParams['causeAgent'] = $this->params['causeAgent'];
85  // Convert this into no more than $wgUpdateRowsPerJob HTMLCacheUpdateJob per-title
86  // jobs and possibly a recursive HTMLCacheUpdateJob job for the rest of the backlinks
88  $this,
90  $wgUpdateRowsPerQuery, // jobs-per-title
91  // Carry over information for de-duplication
92  [ 'params' => $extraParams ]
93  );
94  JobQueueGroup::singleton()->push( $jobs );
95  // Job to purge pages for a set of titles
96  } elseif ( isset( $this->params['pages'] ) ) {
97  $this->invalidateTitles( $this->params['pages'] );
98  // Job to update a single title
99  } else {
100  $t = $this->title;
101  $this->invalidateTitles( [
102  $t->getArticleID() => [ $t->getNamespace(), $t->getDBkey() ]
103  ] );
104  }
105 
106  return true;
107  }
108 
112  protected function invalidateTitles( array $pages ) {
114 
115  // Get all page IDs in this query into an array
116  $pageIds = array_keys( $pages );
117  if ( !$pageIds ) {
118  return;
119  }
120 
121  // Bump page_touched to the current timestamp. This used to use the root job timestamp
122  // (e.g. template/file edit time), which was a bit more efficient when template edits are
123  // rare and don't effect the same pages much. However, this way allows for better
124  // de-duplication, which is much more useful for wikis with high edit rates. Note that
125  // RefreshLinksJob, which is enqueued alongside HTMLCacheUpdateJob, saves the parser output
126  // since it has to parse anyway. We assume that vast majority of the cache jobs finish
127  // before the link jobs, so using the current timestamp instead of the root timestamp is
128  // not expected to invalidate these cache entries too often.
129  $touchTimestamp = wfTimestampNow();
130  // If page_touched is higher than this, then something else already bumped it after enqueue
131  $condTimestamp = $this->params['rootJobTimestamp'] ?? $touchTimestamp;
132 
133  $dbw = wfGetDB( DB_MASTER );
134  $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
135  $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
136  // Update page_touched (skipping pages already touched since the root job).
137  // Check $wgUpdateRowsPerQuery for sanity; batch jobs are sized by that already.
138  foreach ( array_chunk( $pageIds, $wgUpdateRowsPerQuery ) as $batch ) {
139  $factory->commitAndWaitForReplication( __METHOD__, $ticket );
140 
141  $dbw->update( 'page',
142  [ 'page_touched' => $dbw->timestamp( $touchTimestamp ) ],
143  [ 'page_id' => $batch,
144  // don't invalidated pages that were already invalidated
145  "page_touched < " . $dbw->addQuotes( $dbw->timestamp( $condTimestamp ) )
146  ],
147  __METHOD__
148  );
149  }
150  // Get the list of affected pages (races only mean something else did the purge)
151  $titleArray = TitleArray::newFromResult( $dbw->select(
152  'page',
153  array_merge(
154  [ 'page_namespace', 'page_title' ],
155  $wgPageLanguageUseDB ? [ 'page_lang' ] : []
156  ),
157  [ 'page_id' => $pageIds, 'page_touched' => $dbw->timestamp( $touchTimestamp ) ],
158  __METHOD__
159  ) );
160 
161  // Update CDN; call purge() directly so as to not bother with secondary purges
162  $urls = [];
163  foreach ( $titleArray as $title ) {
165  $urls = array_merge( $urls, $title->getCdnUrls() );
166  }
167  CdnCacheUpdate::purge( $urls );
168 
169  // Update file cache
170  if ( $wgUseFileCache ) {
171  foreach ( $titleArray as $title ) {
173  }
174  }
175  }
176 
177  public function getDeduplicationInfo() {
178  $info = parent::getDeduplicationInfo();
179  if ( is_array( $info['params'] ) ) {
180  // For per-pages jobs, the job title is that of the template that changed
181  // (or similar), so remove that since it ruins duplicate detection
182  if ( isset( $info['params']['pages'] ) ) {
183  unset( $info['namespace'] );
184  unset( $info['title'] );
185  }
186  }
187 
188  return $info;
189  }
190 
191  public function workItemCount() {
192  if ( !empty( $this->params['recursive'] ) ) {
193  return 0; // nothing actually purged
194  } elseif ( isset( $this->params['pages'] ) ) {
195  return count( $this->params['pages'] );
196  }
197 
198  return 1; // one title
199  }
200 }
Job\getRootJobParams
getRootJobParams()
Definition: Job.php:279
CdnCacheUpdate\purge
static purge(array $urlArr)
Purges a list of CDN nodes defined in $wgSquidServers.
Definition: CdnCacheUpdate.php:100
TitleArray\newFromResult
static newFromResult( $res)
Definition: TitleArray.php:40
HTMLFileCache\clearFileCache
static clearFileCache(Title $title)
Clear the file caches for a page for all actions.
Definition: HTMLFileCache.php:233
captcha-old.count
count
Definition: captcha-old.py:249
Job\$title
Title $title
Definition: Job.php:41
Job\$params
array $params
Array of job parameters.
Definition: Job.php:35
HTMLCacheUpdateJob\newForBacklinks
static newForBacklinks(Title $title, $table, $params=[])
Definition: HTMLCacheUpdateJob.php:59
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
BacklinkJobUtils\partitionBacklinkJob
static partitionBacklinkJob(Job $job, $bSize, $cSize, $opts=[])
Break down $job into approximately ($bSize/$cSize) leaf jobs and a single partition job that covers t...
Definition: BacklinkJobUtils.php:87
Job
Class to both describe a background job and handle jobs.
Definition: Job.php:30
Title\getCdnUrls
getCdnUrls()
Get a list of URLs to purge from the CDN cache when this page changes.
Definition: Title.php:3945
HTMLCacheUpdateJob\workItemCount
workItemCount()
Definition: HTMLCacheUpdateJob.php:191
$wgUseFileCache
$wgUseFileCache
This will cache static pages for non-logged-in users to reduce database traffic on public sites.
Definition: DefaultSettings.php:2634
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2693
HTMLCacheUpdateJob
Job to purge the cache for all pages that link to or use another page or file.
Definition: HTMLCacheUpdateJob.php:38
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$wgUpdateRowsPerQuery
$wgUpdateRowsPerQuery
Number of rows to update per query.
Definition: DefaultSettings.php:8485
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1983
$wgUpdateRowsPerJob
$wgUpdateRowsPerJob
Number of rows to update per job.
Definition: DefaultSettings.php:8480
DB_MASTER
const DB_MASTER
Definition: defines.php:26
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
Job\newRootJobParams
static newRootJobParams( $key)
Get "root job" parameters for a task.
Definition: Job.php:266
HTMLCacheUpdateJob\invalidateTitles
invalidateTitles(array $pages)
Definition: HTMLCacheUpdateJob.php:112
$wgPageLanguageUseDB
bool $wgPageLanguageUseDB
Enable page language feature Allows setting page language in database.
Definition: DefaultSettings.php:8717
HTMLCacheUpdateJob\getDeduplicationInfo
getDeduplicationInfo()
Subclasses may need to override this to make duplication detection work.
Definition: HTMLCacheUpdateJob.php:177
HTMLCacheUpdateJob\__construct
__construct(Title $title, array $params)
Definition: HTMLCacheUpdateJob.php:39
Title
Represents a title within MediaWiki.
Definition: Title.php:39
JobQueueGroup\singleton
static singleton( $domain=false)
Definition: JobQueueGroup.php:69
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$batch
$batch
Definition: linkcache.txt:23
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:2044
HTMLCacheUpdateJob\run
run()
Run the job.
Definition: HTMLCacheUpdateJob.php:71
$t
$t
Definition: testCompression.php:69
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23