MediaWiki REL1_39
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
42 DeferredUpdates::addUpdate( new AutoCommitUpdate(
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->selectFieldValues(
53 'page',
54 'page_id',
55 [
56 'page_namespace' => $namespace,
57 'page_title' => $dbkeys,
58 'page_touched < ' . $dbw->addQuotes( $now )
59 ],
60 $fname
61 );
62
63 if ( !$ids ) {
64 return;
65 }
66
67 $batchSize =
68 $services->getMainConfig()->get( MainConfigNames::UpdateRowsPerQuery );
69 $ticket = $lbFactory->getEmptyTransactionTicket( $fname );
70 $idBatches = array_chunk( $ids, $batchSize );
71 foreach ( $idBatches as $idBatch ) {
72 $dbw->update(
73 'page',
74 [ 'page_touched' => $now ],
75 [
76 'page_id' => $idBatch,
77 'page_touched < ' . $dbw->addQuotes( $now ) // handle races
78 ],
79 $fname
80 );
81 if ( count( $idBatches ) > 1 ) {
82 $lbFactory->commitAndWaitForReplication( $fname, $ticket );
83 }
84 }
85 }
86 ) );
87 }
88}
Deferrable Update for closure/callback updates that should use auto-commit mode.
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.
addQuotes( $s)
Escape and quote a raw value string for use in a SQL query.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:39
update( $table, $set, $conds, $fname=__METHOD__, $options=[])
Update all rows in a table that match a given condition.
selectFieldValues( $table, $var, $cond='', $fname=__METHOD__, $options=[], $join_conds=[])
A SELECT wrapper which returns a list of single field values from result rows.
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for ins...