MediaWiki master
PurgeJobUtils.php
Go to the documentation of this file.
1<?php
28
38 public static function invalidatePages( IDatabase $dbw, $namespace, array $dbkeys ) {
39 if ( $dbkeys === [] ) {
40 return;
41 }
42 $fname = __METHOD__;
43
44 DeferredUpdates::addUpdate( new AutoCommitUpdate(
45 $dbw,
46 __METHOD__,
47 static function () use ( $dbw, $namespace, $dbkeys, $fname ) {
48 $services = MediaWikiServices::getInstance();
49 $dbProvider = $services->getConnectionProvider();
50 // Determine which pages need to be updated.
51 // This is necessary to prevent the job queue from smashing the DB with
52 // large numbers of concurrent invalidations of the same page.
53 $now = $dbw->timestamp();
54 $ids = $dbw->newSelectQueryBuilder()
55 ->select( 'page_id' )
56 ->from( 'page' )
57 ->where( [ 'page_namespace' => $namespace ] )
58 ->andWhere( [ 'page_title' => $dbkeys ] )
59 ->andWhere( $dbw->expr( 'page_touched', '<', $now ) )
60 ->caller( $fname )->fetchFieldValues();
61
62 if ( !$ids ) {
63 return;
64 }
65
66 $batchSize =
67 $services->getMainConfig()->get( MainConfigNames::UpdateRowsPerQuery );
68 $ticket = $dbProvider->getEmptyTransactionTicket( $fname );
69 $idBatches = array_chunk( $ids, $batchSize );
70 foreach ( $idBatches as $idBatch ) {
72 ->update( 'page' )
73 ->set( [ 'page_touched' => $now ] )
74 ->where( [ 'page_id' => $idBatch ] )
75 ->andWhere( $dbw->expr( 'page_touched', '<', $now ) ) // handle races
76 ->caller( $fname )->execute();
77 if ( count( $idBatches ) > 1 ) {
78 $dbProvider->commitAndWaitForReplication( $fname, $ticket );
79 }
80 }
81 }
82 ) );
83 }
84}
Deferrable Update for closure/callback updates that should use auto-commit mode.
Defer callable updates to run later in the PHP process.
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.
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...