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 );
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' => [ $actorQuery[
'fields'][
'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_map(
'strval', 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() );
228 [
'qci_type' =>
'activeusers',
229 'qci_timestamp' => $dbw->timestamp( $asOfTimestamp ) ],
233 $dbw->unlock( $lockKey, __METHOD__ );
236 $dbw->delete(
'querycachetwo',
238 'qcc_type' =>
'activeusers',
239 'qcc_value < ' . $dbw->addQuotes( $nowUnix - $days * 86400 )