3 * Base code for update jobs that put some secondary data extracted
4 * from article content into the database.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
23 use Wikimedia\Rdbms\IDatabase
;
24 use MediaWiki\MediaWikiServices
;
28 * Invalidate the cache of a list of pages from a single namespace.
29 * This is intended for use by subclasses.
31 * @param IDatabase $dbw
32 * @param int $namespace Namespace number
33 * @param array $dbkeys
35 public static function invalidatePages( IDatabase
$dbw, $namespace, array $dbkeys ) {
36 if ( $dbkeys === [] ) {
40 DeferredUpdates
::addUpdate( new AutoCommitUpdate(
43 function () use ( $dbw, $namespace, $dbkeys ) {
44 $services = MediaWikiServices
::getInstance();
45 $lbFactory = $services->getDBLoadBalancerFactory();
46 // Determine which pages need to be updated.
47 // This is necessary to prevent the job queue from smashing the DB with
48 // large numbers of concurrent invalidations of the same page.
49 $now = $dbw->timestamp();
50 $ids = $dbw->selectFieldValues(
54 'page_namespace' => $namespace,
55 'page_title' => $dbkeys,
56 'page_touched < ' . $dbw->addQuotes( $now )
65 $batchSize = $services->getMainConfig()->get( 'UpdateRowsPerQuery' );
66 $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__
);
67 foreach ( array_chunk( $ids, $batchSize ) as $idBatch ) {
70 [ 'page_touched' => $now ],
72 'page_id' => $idBatch,
73 'page_touched < ' . $dbw->addQuotes( $now ) // handle races
77 $lbFactory->commitAndWaitForReplication( __METHOD__
, $ticket );