77 $lockKey = $dbw->getDomainID() .
':recentchanges-prune';
78 if ( !$dbw->lock( $lockKey, __METHOD__, 0 ) ) {
83 $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
84 $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
86 $rcQuery = RecentChange::getQueryInfo();
93 [
'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ],
98 foreach (
$res as $row ) {
99 $rcIds[] = $row->rc_id;
103 $dbw->delete(
'recentchanges', [
'rc_id' => $rcIds ], __METHOD__ );
104 Hooks::runner()->onRecentChangesPurgeRows( $rows );
106 if ( !$factory->commitAndWaitForReplication(
107 __METHOD__, $ticket, [
'timeout' => 3 ]
115 $dbw->unlock( $lockKey, __METHOD__ );
127 $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
128 $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
130 $lockKey = $dbw->getDomainID() .
'-activeusers';
131 if ( !$dbw->lock( $lockKey, __METHOD__, 0 ) ) {
138 $dbw->setSessionOptions( [
'connTimeout' => 900 ] );
142 $cTime = $dbw->selectField(
'querycache_info',
144 [
'qci_type' =>
'activeusers' ],
147 $cTimeUnix = $cTime ?
wfTimestamp( TS_UNIX, $cTime ) : 1;
152 $sTimestamp = max( $cTimeUnix, $nowUnix - $days * 86400 );
153 $eTimestamp = min( $sTimestamp + $window, $nowUnix );
157 [
'recentchanges',
'actor' ],
160 'lastedittime' =>
'MAX(rc_timestamp)'
163 'actor_user IS NOT NULL',
165 'rc_log_type IS NULL OR rc_log_type != ' . $dbw->addQuotes(
'newusers' ),
166 'rc_timestamp >= ' . $dbw->addQuotes( $dbw->timestamp( $sTimestamp ) ),
167 'rc_timestamp <= ' . $dbw->addQuotes( $dbw->timestamp( $eTimestamp ) )
171 'GROUP BY' =>
'actor_name',
175 'actor' => [
'JOIN',
'actor_id=rc_actor' ]
179 foreach (
$res as $row ) {
180 $names[$row->actor_name] = $row->lastedittime;
184 if ( count( $names ) ) {
185 $res = $dbw->select(
'querycachetwo',
186 [
'user_name' =>
'qcc_title' ],
188 'qcc_type' =>
'activeusers',
190 'qcc_title' => array_map(
'strval', array_keys( $names ) ),
191 'qcc_value >= ' . $dbw->addQuotes( $nowUnix - $days * 86400 ),
197 foreach (
$res as $row ) {
198 unset( $names[$row->user_name] );
203 if ( count( $names ) ) {
205 foreach ( $names as $name => $lastEditTime ) {
207 'qcc_type' =>
'activeusers',
209 'qcc_title' => $name,
210 'qcc_value' =>
wfTimestamp( TS_UNIX, $lastEditTime ),
211 'qcc_namespacetwo' => 0,
215 foreach ( array_chunk( $newRows, 500 ) as $rowBatch ) {
216 $dbw->insert(
'querycachetwo', $rowBatch, __METHOD__ );
217 $factory->commitAndWaitForReplication( __METHOD__, $ticket );
223 $asOfTimestamp = min( $eTimestamp, (
int)$dbw->trxTimestamp() );
229 [
'qci_type' =>
'activeusers',
230 'qci_timestamp' => $dbw->timestamp( $asOfTimestamp ) ],
235 $dbw->delete(
'querycachetwo',
237 'qcc_type' =>
'activeusers',
238 'qcc_value < ' . $dbw->addQuotes( $nowUnix - $days * 86400 )
243 $dbw->unlock( $lockKey, __METHOD__ );