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