Merge branch 'Wikidata', remote-tracking branch 'origin/Wikidata' into Wikidata
[mediawiki.git] / includes / SecondaryDBDataUpdate.php
blob1adb9a35245901e7415bc848f578338b89533a8f
1 <?php
2 /**
3 * See docs/deferred.txt
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * Abstract base class for update jobs that put some secondary data extracted
21 * from article content into the database.
23 abstract class SecondaryDBDataUpdate extends SecondaryDataUpdate {
25 /**@{{
26 * @private
28 var $mDb, //!< Database connection reference
29 $mOptions; //!< SELECT options to be used (array)
30 /**@}}*/
32 /**
33 * Constructor
34 **/
35 public function __construct( ) {
36 global $wgAntiLockFlags;
38 parent::__construct( );
40 if ( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) {
41 $this->mOptions = array();
42 } else {
43 $this->mOptions = array( 'FOR UPDATE' );
45 $this->mDb = wfGetDB( DB_MASTER );
48 /**
49 * Invalidate the cache of a list of pages from a single namespace
51 * @param $namespace Integer
52 * @param $dbkeys Array
54 public function invalidatePages( $namespace, $dbkeys ) {
55 if ( !count( $dbkeys ) ) {
56 return;
59 /**
60 * Determine which pages need to be updated
61 * This is necessary to prevent the job queue from smashing the DB with
62 * large numbers of concurrent invalidations of the same page
64 $now = $this->mDb->timestamp();
65 $ids = array();
66 $res = $this->mDb->select( 'page', array( 'page_id' ),
67 array(
68 'page_namespace' => $namespace,
69 'page_title IN (' . $this->mDb->makeList( $dbkeys ) . ')',
70 'page_touched < ' . $this->mDb->addQuotes( $now )
71 ), __METHOD__
73 foreach ( $res as $row ) {
74 $ids[] = $row->page_id;
76 if ( !count( $ids ) ) {
77 return;
80 /**
81 * Do the update
82 * We still need the page_touched condition, in case the row has changed since
83 * the non-locking select above.
85 $this->mDb->update( 'page', array( 'page_touched' => $now ),
86 array(
87 'page_id IN (' . $this->mDb->makeList( $ids ) . ')',
88 'page_touched < ' . $this->mDb->addQuotes( $now )
89 ), __METHOD__