MediaWiki REL1_30
PurgeJobUtils.php
Go to the documentation of this file.
1<?php
25
35 public static function invalidatePages( IDatabase $dbw, $namespace, array $dbkeys ) {
36 if ( $dbkeys === [] ) {
37 return;
38 }
39
41 function () use ( $dbw, $namespace, $dbkeys ) {
42 $services = MediaWikiServices::getInstance();
43 $lbFactory = $services->getDBLoadBalancerFactory();
44 // Determine which pages need to be updated.
45 // This is necessary to prevent the job queue from smashing the DB with
46 // large numbers of concurrent invalidations of the same page.
47 $now = $dbw->timestamp();
48 $ids = $dbw->selectFieldValues(
49 'page',
50 'page_id',
51 [
52 'page_namespace' => $namespace,
53 'page_title' => $dbkeys,
54 'page_touched < ' . $dbw->addQuotes( $now )
55 ],
56 __METHOD__
57 );
58
59 if ( !$ids ) {
60 return;
61 }
62
63 $batchSize = $services->getMainConfig()->get( 'UpdateRowsPerQuery' );
64 $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
65 foreach ( array_chunk( $ids, $batchSize ) as $idBatch ) {
66 $dbw->update(
67 'page',
68 [ 'page_touched' => $now ],
69 [
70 'page_id' => $idBatch,
71 'page_touched < ' . $dbw->addQuotes( $now ) // handle races
72 ],
73 __METHOD__
74 );
75 $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
76 }
77 },
78 __METHOD__
79 );
80 }
81}
MediaWikiServices is the service locator for the application scope of MediaWiki.
static invalidatePages(IDatabase $dbw, $namespace, array $dbkeys)
Invalidate the cache of a list of pages from a single namespace.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Definition hooks.txt:2243
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:40
addQuotes( $s)
Adds quotes and backslashes.
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
update( $table, $values, $conds, $fname=__METHOD__, $options=[])
UPDATE wrapper.
selectFieldValues( $table, $var, $cond='', $fname=__METHOD__, $options=[], $join_conds=[])
A SELECT wrapper which returns a list of single field values from result rows.
onTransactionIdle(callable $callback, $fname=__METHOD__)
Run a callback as soon as there is no transaction pending.