MediaWiki  1.34.0
PurgeJobUtils.php
Go to the documentation of this file.
1 <?php
25 
35  public static function invalidatePages( IDatabase $dbw, $namespace, array $dbkeys ) {
36  if ( $dbkeys === [] ) {
37  return;
38  }
39  $fname = __METHOD__;
40 
42  $dbw,
43  __METHOD__,
44  function () use ( $dbw, $namespace, $dbkeys, $fname ) {
45  $services = MediaWikiServices::getInstance();
46  $lbFactory = $services->getDBLoadBalancerFactory();
47  // Determine which pages need to be updated.
48  // This is necessary to prevent the job queue from smashing the DB with
49  // large numbers of concurrent invalidations of the same page.
50  $now = $dbw->timestamp();
51  $ids = $dbw->selectFieldValues(
52  'page',
53  'page_id',
54  [
55  'page_namespace' => $namespace,
56  'page_title' => $dbkeys,
57  'page_touched < ' . $dbw->addQuotes( $now )
58  ],
59  $fname
60  );
61 
62  if ( !$ids ) {
63  return;
64  }
65 
66  $batchSize = $services->getMainConfig()->get( 'UpdateRowsPerQuery' );
67  $ticket = $lbFactory->getEmptyTransactionTicket( $fname );
68  $idBatches = array_chunk( $ids, $batchSize );
69  foreach ( $idBatches as $idBatch ) {
70  $dbw->update(
71  'page',
72  [ 'page_touched' => $now ],
73  [
74  'page_id' => $idBatch,
75  'page_touched < ' . $dbw->addQuotes( $now ) // handle races
76  ],
77  $fname
78  );
79  if ( count( $idBatches ) > 1 ) {
80  $lbFactory->commitAndWaitForReplication( $fname, $ticket );
81  }
82  }
83  }
84  ) );
85  }
86 }
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
AutoCommitUpdate
Deferrable Update for closure/callback updates that should use auto-commit mode.
Definition: AutoCommitUpdate.php:9
DeferredUpdates\addUpdate
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the deferred list to be run later by execute()
Definition: DeferredUpdates.php:85
PurgeJobUtils\invalidatePages
static invalidatePages(IDatabase $dbw, $namespace, array $dbkeys)
Invalidate the cache of a list of pages from a single namespace.
Definition: PurgeJobUtils.php:35
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
Wikimedia\Rdbms\IDatabase\timestamp
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for ins...
PurgeJobUtils
Definition: PurgeJobUtils.php:26
Wikimedia\Rdbms\IDatabase\update
update( $table, $values, $conds, $fname=__METHOD__, $options=[])
UPDATE wrapper.
Wikimedia\Rdbms\IDatabase\addQuotes
addQuotes( $s)
Escape and quote a raw value string for use in a SQL query.
Wikimedia\Rdbms\IDatabase\selectFieldValues
selectFieldValues( $table, $var, $cond='', $fname=__METHOD__, $options=[], $join_conds=[])
A SELECT wrapper which returns a list of single field values from result rows.