MediaWiki  master
PurgeJobUtils.php
Go to the documentation of this file.
1 <?php
26 
36  public static function invalidatePages( IDatabase $dbw, $namespace, array $dbkeys ) {
37  if ( $dbkeys === [] ) {
38  return;
39  }
40  $fname = __METHOD__;
41 
43  $dbw,
44  __METHOD__,
45  static function () use ( $dbw, $namespace, $dbkeys, $fname ) {
46  $services = MediaWikiServices::getInstance();
47  $lbFactory = $services->getDBLoadBalancerFactory();
48  // Determine which pages need to be updated.
49  // This is necessary to prevent the job queue from smashing the DB with
50  // large numbers of concurrent invalidations of the same page.
51  $now = $dbw->timestamp();
52  $ids = $dbw->newSelectQueryBuilder()
53  ->select( 'page_id' )
54  ->from( 'page' )
55  ->where( [ 'page_namespace' => $namespace ] )
56  ->andWhere( [ 'page_title' => $dbkeys ] )
57  ->andWhere( $dbw->buildComparison( '<', [ 'page_touched' => $now ] ) )
58  ->caller( $fname )->fetchFieldValues();
59 
60  if ( !$ids ) {
61  return;
62  }
63 
64  $batchSize =
65  $services->getMainConfig()->get( MainConfigNames::UpdateRowsPerQuery );
66  $ticket = $lbFactory->getEmptyTransactionTicket( $fname );
67  $idBatches = array_chunk( $ids, $batchSize );
68  foreach ( $idBatches as $idBatch ) {
69  $dbw->newUpdateQueryBuilder()
70  ->update( 'page' )
71  ->set( [ 'page_touched' => $now ] )
72  ->where( [ 'page_id' => $idBatch ] )
73  ->andWhere( $dbw->buildComparison( '<', [ 'page_touched' => $now ] ) ) // handle races
74  ->caller( $fname )->execute();
75  if ( count( $idBatches ) > 1 ) {
76  $lbFactory->commitAndWaitForReplication( $fname, $ticket );
77  }
78  }
79  }
80  ) );
81  }
82 }
Deferrable Update for closure/callback updates that should use auto-commit mode.
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the pending update queue for execution at the appropriate time.
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
static invalidatePages(IDatabase $dbw, $namespace, array $dbkeys)
Invalidate the cache of a list of pages from a single namespace.
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:36
newUpdateQueryBuilder()
Get an UpdateQueryBuilder bound to this connection.
newSelectQueryBuilder()
Create an empty SelectQueryBuilder which can be used to run queries against this connection.
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for ins...
buildComparison(string $op, array $conds)
Build a condition comparing multiple values, for use with indexes that cover multiple fields,...