76 $lockKey =
wfWikiID() .
':recentchanges-prune';
79 if ( !$dbw->lock( $lockKey, __METHOD__, 0 ) ) {
84 $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
85 $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
87 $rcQuery = RecentChange::getQueryInfo();
94 [
'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ],
100 $rcIds[] = $row->rc_id;
104 $dbw->delete(
'recentchanges', [
'rc_id' => $rcIds ], __METHOD__ );
105 Hooks::run(
'RecentChangesPurgeRows', [
$rows ] );
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 );
156 $actorQuery = ActorMigration::newMigration()->getJoin(
'rc_user' );
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 )