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::run(
'RecentChangesPurgeRows', [ $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' ]
146 $cTimeUnix = $cTime ?
wfTimestamp( TS_UNIX, $cTime ) : 1;
151 $sTimestamp = max( $cTimeUnix, $nowUnix - $days * 86400 );
152 $eTimestamp = min( $sTimestamp + $window, $nowUnix );
155 $actorQuery = ActorMigration::newMigration()->getJoin(
'rc_user' );
157 [
'recentchanges' ] + $actorQuery[
'tables'],
159 'rc_user_text' => $actorQuery[
'fields'][
'rc_user_text'],
160 'lastedittime' =>
'MAX(rc_timestamp)'
163 $actorQuery[
'fields'][
'rc_user'] .
' > 0',
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' => [ $actorQuery[
'fields'][
'rc_user_text'] ],
177 foreach (
$res as $row ) {
178 $names[$row->rc_user_text] = $row->lastedittime;
182 if ( count( $names ) ) {
183 $res = $dbw->select(
'querycachetwo',
184 [
'user_name' =>
'qcc_title' ],
186 'qcc_type' =>
'activeusers',
188 'qcc_title' => array_keys( $names ),
189 'qcc_value >= ' . $dbw->addQuotes( $nowUnix - $days * 86400 ),
195 foreach (
$res as $row ) {
196 unset( $names[$row->user_name] );
201 if ( count( $names ) ) {
203 foreach ( $names as $name => $lastEditTime ) {
205 'qcc_type' =>
'activeusers',
207 'qcc_title' => $name,
208 'qcc_value' =>
wfTimestamp( TS_UNIX, $lastEditTime ),
209 'qcc_namespacetwo' => 0,
213 foreach ( array_chunk( $newRows, 500 ) as $rowBatch ) {
214 $dbw->insert(
'querycachetwo', $rowBatch, __METHOD__ );
215 $factory->commitAndWaitForReplication( __METHOD__, $ticket );
221 $asOfTimestamp = min( $eTimestamp, (
int)$dbw->trxTimestamp() );
224 $dbw->replace(
'querycache_info',
226 [
'qci_type' =>
'activeusers',
227 'qci_timestamp' => $dbw->timestamp( $asOfTimestamp ) ],
231 $dbw->unlock( $lockKey, __METHOD__ );
234 $dbw->delete(
'querycachetwo',
236 'qcc_type' =>
'activeusers',
237 'qcc_value < ' . $dbw->addQuotes( $nowUnix - $days * 86400 )