MediaWiki master
PurgeJobUtils.php
Go to the documentation of this file.
1<?php
22
28
45 public static function invalidatePages( IDatabase $dbw, $namespace, array $dbkeys ) {
46 if ( $dbkeys === [] ) {
47 return;
48 }
49 $fname = __METHOD__;
50
51 DeferredUpdates::addUpdate( new AutoCommitUpdate(
52 $dbw,
53 __METHOD__,
54 static function () use ( $dbw, $namespace, $dbkeys, $fname ) {
56 $dbProvider = $services->getConnectionProvider();
57 // Determine which pages need to be updated.
58 // This is necessary to prevent the job queue from smashing the DB with
59 // large numbers of concurrent invalidations of the same page.
60 $now = $dbw->timestamp();
61 $ids = $dbw->newSelectQueryBuilder()
62 ->select( 'page_id' )
63 ->from( 'page' )
64 ->where( [ 'page_namespace' => $namespace ] )
65 ->andWhere( [ 'page_title' => $dbkeys ] )
66 ->andWhere( $dbw->expr( 'page_touched', '<', $now ) )
67 ->caller( $fname )->fetchFieldValues();
68
69 if ( !$ids ) {
70 return;
71 }
72
73 $batchSize =
74 $services->getMainConfig()->get( MainConfigNames::UpdateRowsPerQuery );
75 $ticket = $dbProvider->getEmptyTransactionTicket( $fname );
76 $idBatches = array_chunk( $ids, $batchSize );
77 foreach ( $idBatches as $idBatch ) {
79 ->update( 'page' )
80 ->set( [ 'page_touched' => $now ] )
81 ->where( [ 'page_id' => $idBatch ] )
82 ->andWhere( $dbw->expr( 'page_touched', '<', $now ) ) // handle races
83 ->caller( $fname )->execute();
84 if ( count( $idBatches ) > 1 ) {
85 $dbProvider->commitAndWaitForReplication( $fname, $ticket );
86 }
87 }
88 }
89 ) );
90 }
91}
92
94class_alias( PurgeJobUtils::class, 'PurgeJobUtils' );
Deferrable Update for closure/callback updates that should use auto-commit mode.
Defer callable updates to run later in the PHP process.
Helper for a Job that writes data derived from page content to the database.
static invalidatePages(IDatabase $dbw, $namespace, array $dbkeys)
Invalidate the cache of a list of pages from a single namespace.
A class containing constants representing the names of configuration variables.
const UpdateRowsPerQuery
Name constant for the UpdateRowsPerQuery setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Interface to a relational database.
Definition IDatabase.php:45
newUpdateQueryBuilder()
Get an UpdateQueryBuilder bound to this connection.
newSelectQueryBuilder()
Create an empty SelectQueryBuilder which can be used to run queries against this connection.
expr(string $field, string $op, $value)
See Expression::__construct()
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for ins...