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
19 * @author Aaron Schulz
24 * Job for pruning recent changes
29 class RecentChangesUpdateJob
extends Job
{
30 function __construct( $title, $params ) {
31 parent
::__construct( 'recentChangesUpdate', $title, $params );
33 if ( !isset( $params['type'] ) ) {
34 throw new Exception( "Missing 'type' parameter." );
37 $this->removeDuplicates
= true;
41 * @return RecentChangesUpdateJob
43 final public static function newPurgeJob() {
45 SpecialPage
::getTitleFor( 'Recentchanges' ), array( 'type' => 'purge' )
49 public function run() {
50 if ( $this->params
['type'] === 'purge' ) {
51 $this->purgeExpiredRows();
53 throw new Exception( "Invalid 'type' parameter '{$this->params['type']}'." );
59 protected function purgeExpiredRows() {
62 $lockKey = wfWikiID() . ':recentchanges-prune';
64 $dbw = wfGetDB( DB_MASTER
);
65 if ( !$dbw->lock( $lockKey, __METHOD__
, 1 ) ) {
66 return; // already in progress
68 $batchSize = 100; // Avoid slave lag
70 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
72 $rcIds = $dbw->selectFieldValues( 'recentchanges',
74 array( 'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ),
76 array( 'LIMIT' => $batchSize )
79 $dbw->delete( 'recentchanges', array( 'rc_id' => $rcIds ), __METHOD__
);
81 // No need for this to be in a transaction.
82 $dbw->commit( __METHOD__
, 'flush' );
84 if ( count( $rcIds ) === $batchSize ) {
85 // There might be more, so try waiting for slaves
86 if ( !wfWaitForSlaves( null, false, false, /* $timeout = */ 3 ) ) {
87 // Another job will continue anyway
93 $dbw->unlock( $lockKey, __METHOD__
);