3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
20 use MediaWiki\Deferred\AutoCommitUpdate
;
21 use MediaWiki\Deferred\DeferredUpdates
;
22 use MediaWiki\MainConfigNames
;
23 use MediaWiki\MediaWikiServices
;
24 use Wikimedia\Rdbms\IDatabase
;
27 * Helper for a Job that writes data derived from page content to the database.
29 * Used by RefreshLinksJob via LinksUpdate.
35 * Invalidate the cache of a list of pages from a single namespace.
36 * This is intended for use by subclasses.
38 * @param IDatabase $dbw
39 * @param int $namespace Namespace number
40 * @param string[] $dbkeys
42 public static function invalidatePages( IDatabase
$dbw, $namespace, array $dbkeys ) {
43 if ( $dbkeys === [] ) {
48 DeferredUpdates
::addUpdate( new AutoCommitUpdate(
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()
61 ->where( [ 'page_namespace' => $namespace ] )
62 ->andWhere( [ 'page_title' => $dbkeys ] )
63 ->andWhere( $dbw->expr( 'page_touched', '<', $now ) )
64 ->caller( $fname )->fetchFieldValues();
71 $services->getMainConfig()->get( MainConfigNames
::UpdateRowsPerQuery
);
72 $ticket = $dbProvider->getEmptyTransactionTicket( $fname );
73 $idBatches = array_chunk( $ids, $batchSize );
74 foreach ( $idBatches as $idBatch ) {
75 $dbw->newUpdateQueryBuilder()
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 );