MediaWiki  1.29.2
HTMLCacheUpdateJob.php
Go to the documentation of this file.
1 <?php
26 
38 class HTMLCacheUpdateJob extends Job {
40  parent::__construct( 'htmlCacheUpdate', $title, $params );
41  // Base backlink purge jobs can be de-duplicated
42  $this->removeDuplicates = ( !isset( $params['range'] ) && !isset( $params['pages'] ) );
43  }
44 
50  public static function newForBacklinks( Title $title, $table ) {
51  return new self(
52  $title,
53  [
54  'table' => $table,
55  'recursive' => true
56  ] + Job::newRootJobParams( // "overall" refresh links job info
57  "htmlCacheUpdate:{$table}:{$title->getPrefixedText()}"
58  )
59  );
60  }
61 
62  function run() {
63  global $wgUpdateRowsPerJob, $wgUpdateRowsPerQuery;
64 
65  if ( isset( $this->params['table'] ) && !isset( $this->params['pages'] ) ) {
66  $this->params['recursive'] = true; // b/c; base job
67  }
68 
69  // Job to purge all (or a range of) backlink pages for a page
70  if ( !empty( $this->params['recursive'] ) ) {
71  // Convert this into no more than $wgUpdateRowsPerJob HTMLCacheUpdateJob per-title
72  // jobs and possibly a recursive HTMLCacheUpdateJob job for the rest of the backlinks
74  $this,
75  $wgUpdateRowsPerJob,
76  $wgUpdateRowsPerQuery, // jobs-per-title
77  // Carry over information for de-duplication
78  [ 'params' => $this->getRootJobParams() ]
79  );
80  JobQueueGroup::singleton()->push( $jobs );
81  // Job to purge pages for a set of titles
82  } elseif ( isset( $this->params['pages'] ) ) {
83  $this->invalidateTitles( $this->params['pages'] );
84  // Job to update a single title
85  } else {
86  $t = $this->title;
87  $this->invalidateTitles( [
88  $t->getArticleID() => [ $t->getNamespace(), $t->getDBkey() ]
89  ] );
90  }
91 
92  return true;
93  }
94 
98  protected function invalidateTitles( array $pages ) {
99  global $wgUpdateRowsPerQuery, $wgUseFileCache;
100 
101  // Get all page IDs in this query into an array
102  $pageIds = array_keys( $pages );
103  if ( !$pageIds ) {
104  return;
105  }
106 
107  // Bump page_touched to the current timestamp. This used to use the root job timestamp
108  // (e.g. template/file edit time), which was a bit more efficient when template edits are
109  // rare and don't effect the same pages much. However, this way allows for better
110  // de-duplication, which is much more useful for wikis with high edit rates. Note that
111  // RefreshLinksJob, which is enqueued alongside HTMLCacheUpdateJob, saves the parser output
112  // since it has to parse anyway. We assume that vast majority of the cache jobs finish
113  // before the link jobs, so using the current timestamp instead of the root timestamp is
114  // not expected to invalidate these cache entries too often.
115  $touchTimestamp = wfTimestampNow();
116 
117  $dbw = wfGetDB( DB_MASTER );
118  $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
119  $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
120  // Update page_touched (skipping pages already touched since the root job).
121  // Check $wgUpdateRowsPerQuery for sanity; batch jobs are sized by that already.
122  foreach ( array_chunk( $pageIds, $wgUpdateRowsPerQuery ) as $batch ) {
123  $factory->commitAndWaitForReplication( __METHOD__, $ticket );
124 
125  $dbw->update( 'page',
126  [ 'page_touched' => $dbw->timestamp( $touchTimestamp ) ],
127  [ 'page_id' => $batch,
128  // don't invalidated pages that were already invalidated
129  "page_touched < " . $dbw->addQuotes( $dbw->timestamp( $touchTimestamp ) )
130  ],
131  __METHOD__
132  );
133  }
134  // Get the list of affected pages (races only mean something else did the purge)
135  $titleArray = TitleArray::newFromResult( $dbw->select(
136  'page',
137  [ 'page_namespace', 'page_title' ],
138  [ 'page_id' => $pageIds, 'page_touched' => $dbw->timestamp( $touchTimestamp ) ],
139  __METHOD__
140  ) );
141 
142  // Update CDN
143  $u = CdnCacheUpdate::newFromTitles( $titleArray );
144  $u->doUpdate();
145 
146  // Update file cache
147  if ( $wgUseFileCache ) {
148  foreach ( $titleArray as $title ) {
150  }
151  }
152  }
153 
154  public function workItemCount() {
155  return isset( $this->params['pages'] ) ? count( $this->params['pages'] ) : 1;
156  }
157 }
Job\getRootJobParams
getRootJobParams()
Definition: Job.php:274
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:232
captcha-old.count
count
Definition: captcha-old.py:225
HTMLCacheUpdateJob\newForBacklinks
static newForBacklinks(Title $title, $table)
Definition: HTMLCacheUpdateJob.php:50
Job\$title
Title $title
Definition: Job.php:42
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
Job\$params
array $params
Array of job parameters.
Definition: Job.php:36
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:88
Job
Class to both describe a background job and handle jobs.
Definition: Job.php:31
HTMLCacheUpdateJob\workItemCount
workItemCount()
Definition: HTMLCacheUpdateJob.php:154
$wgUseFileCache
$wgUseFileCache
This will cache static pages for non-logged-in users to reduce database traffic on public sites.
Definition: DefaultSettings.php:2532
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3060
HTMLCacheUpdateJob
Job to purge the cache for all pages that link to or use another page or file.
Definition: HTMLCacheUpdateJob.php:38
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:2023
DB_MASTER
const DB_MASTER
Definition: defines.php:26
Job\newRootJobParams
static newRootJobParams( $key)
Get "root job" parameters for a task.
Definition: Job.php:261
HTMLCacheUpdateJob\invalidateTitles
invalidateTitles(array $pages)
Definition: HTMLCacheUpdateJob.php:98
CdnCacheUpdate\newFromTitles
static newFromTitles( $titles, $urlArr=[])
Create an update object from an array of Title objects, or a TitleArray object.
Definition: CdnCacheUpdate.php:56
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( $wiki=false)
Definition: JobQueueGroup.php:71
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:1956
HTMLCacheUpdateJob\run
run()
Run the job.
Definition: HTMLCacheUpdateJob.php:62
$t
$t
Definition: testCompression.php:67
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
array
the array() calling protocol came about after MediaWiki 1.4rc1.