31 parent::__construct(
'recentChangesUpdate',
$title,
$params );
33 if ( !isset(
$params[
'type'] ) ) {
34 throw new Exception(
"Missing 'type' parameter." );
37 $this->executionFlags |= self::JOB_NO_EXPLICIT_TRX_ROUND;
38 $this->removeDuplicates =
true;
60 public function run() {
61 if ( $this->params[
'type'] ===
'purge' ) {
63 } elseif ( $this->params[
'type'] ===
'cacheUpdate' ) {
66 throw new InvalidArgumentException(
67 "Invalid 'type' parameter '{$this->params['type']}'." );
76 $lockKey =
wfWikiID() .
':recentchanges-prune';
79 if ( !$dbw->lock( $lockKey, __METHOD__, 0 ) ) {
84 $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
85 $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
94 [
'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ],
100 $rcIds[] = $row->rc_id;
104 $dbw->delete(
'recentchanges', [
'rc_id' => $rcIds ], __METHOD__ );
107 if ( !$factory->commitAndWaitForReplication(
108 __METHOD__, $ticket, [
'timeout' => 3 ]
116 $dbw->unlock( $lockKey, __METHOD__ );
128 $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
129 $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
131 $lockKey =
wfWikiID() .
'-activeusers';
132 if ( !$dbw->lock( $lockKey, __METHOD__, 0 ) ) {
139 $dbw->setSessionOptions( [
'connTimeout' => 900 ] );
143 $cTime = $dbw->selectField(
'querycache_info',
145 [
'qci_type' =>
'activeusers' ]
147 $cTimeUnix = $cTime ?
wfTimestamp( TS_UNIX, $cTime ) : 1;
152 $sTimestamp = max( $cTimeUnix, $nowUnix - $days * 86400 );
153 $eTimestamp = min( $sTimestamp + $window, $nowUnix );
158 [
'recentchanges' ] + $actorQuery[
'tables'],
160 'rc_user_text' => $actorQuery[
'fields'][
'rc_user_text'],
161 'lastedittime' =>
'MAX(rc_timestamp)'
164 $actorQuery[
'fields'][
'rc_user'] .
' > 0',
166 'rc_log_type IS NULL OR rc_log_type != ' . $dbw->addQuotes(
'newusers' ),
167 'rc_timestamp >= ' . $dbw->addQuotes( $dbw->timestamp( $sTimestamp ) ),
168 'rc_timestamp <= ' . $dbw->addQuotes( $dbw->timestamp( $eTimestamp ) )
172 'GROUP BY' => [
'rc_user_text' ],
178 foreach (
$res as $row ) {
179 $names[$row->rc_user_text] = $row->lastedittime;
183 if (
count( $names ) ) {
184 $res = $dbw->select(
'querycachetwo',
185 [
'user_name' =>
'qcc_title' ],
187 'qcc_type' =>
'activeusers',
189 'qcc_title' => array_keys( $names ),
190 'qcc_value >= ' . $dbw->addQuotes( $nowUnix - $days * 86400 ),
196 foreach (
$res as $row ) {
197 unset( $names[$row->user_name] );
202 if (
count( $names ) ) {
204 foreach ( $names
as $name => $lastEditTime ) {
206 'qcc_type' =>
'activeusers',
208 'qcc_title' =>
$name,
209 'qcc_value' =>
wfTimestamp( TS_UNIX, $lastEditTime ),
210 'qcc_namespacetwo' => 0,
214 foreach ( array_chunk( $newRows, 500 )
as $rowBatch ) {
215 $dbw->insert(
'querycachetwo', $rowBatch, __METHOD__ );
216 $factory->commitAndWaitForReplication( __METHOD__, $ticket );
222 $asOfTimestamp = min( $eTimestamp, (
int)$dbw->trxTimestamp() );
225 $dbw->replace(
'querycache_info',
227 [
'qci_type' =>
'activeusers',
228 'qci_timestamp' => $dbw->timestamp( $asOfTimestamp ) ],
232 $dbw->unlock( $lockKey, __METHOD__ );
235 $dbw->delete(
'querycachetwo',
237 'qcc_type' =>
'activeusers',
238 'qcc_value < ' . $dbw->addQuotes( $nowUnix - $days * 86400 )