MediaWiki master
PurgeJobUtils.php
Go to the documentation of this file.
1<?php
8
14
31 public static function invalidatePages( IDatabase $dbw, $namespace, array $dbkeys ) {
32 if ( $dbkeys === [] ) {
33 return;
34 }
35 $fname = __METHOD__;
36
37 DeferredUpdates::addUpdate( new AutoCommitUpdate(
38 $dbw,
39 __METHOD__,
40 static function () use ( $dbw, $namespace, $dbkeys, $fname ) {
42 $dbProvider = $services->getConnectionProvider();
43 // Determine which pages need to be updated.
44 // This is necessary to prevent the job queue from smashing the DB with
45 // large numbers of concurrent invalidations of the same page.
46 $now = $dbw->timestamp();
47 $ids = $dbw->newSelectQueryBuilder()
48 ->select( 'page_id' )
49 ->from( 'page' )
50 ->where( [ 'page_namespace' => $namespace ] )
51 ->andWhere( [ 'page_title' => $dbkeys ] )
52 ->andWhere( $dbw->expr( 'page_touched', '<', $now ) )
53 ->caller( $fname )->fetchFieldValues();
54
55 if ( !$ids ) {
56 return;
57 }
58
59 $batchSize =
60 $services->getMainConfig()->get( MainConfigNames::UpdateRowsPerQuery );
61 $ticket = $dbProvider->getEmptyTransactionTicket( $fname );
62 $idBatches = array_chunk( $ids, $batchSize );
63 foreach ( $idBatches as $idBatch ) {
65 ->update( 'page' )
66 ->set( [ 'page_touched' => $now ] )
67 ->where( [ 'page_id' => $idBatch ] )
68 ->andWhere( $dbw->expr( 'page_touched', '<', $now ) ) // handle races
69 ->caller( $fname )->execute();
70 if ( count( $idBatches ) > 1 ) {
71 $dbProvider->commitAndWaitForReplication( $fname, $ticket );
72 }
73 }
74 }
75 ) );
76 }
77}
78
80class_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:31
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...