76 $rcMaxAge = MediaWikiServices::getInstance()->getMainConfig()->get(
77 MainConfigNames::RCMaxAge );
78 $updateRowsPerQuery = MediaWikiServices::getInstance()->getMainConfig()->get(
79 MainConfigNames::UpdateRowsPerQuery );
81 $lockKey = $dbw->getDomainID() .
':recentchanges-prune';
82 if ( !$dbw->lock( $lockKey, __METHOD__, 0 ) ) {
87 $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
88 $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
89 $cutoff = $dbw->timestamp( time() - $rcMaxAge );
90 $rcQuery = RecentChange::getQueryInfo();
97 [
'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ],
99 [
'LIMIT' => $updateRowsPerQuery ],
102 foreach (
$res as $row ) {
103 $rcIds[] = $row->rc_id;
107 $dbw->delete(
'recentchanges', [
'rc_id' => $rcIds ], __METHOD__ );
108 Hooks::runner()->onRecentChangesPurgeRows( $rows );
110 if ( !$factory->commitAndWaitForReplication(
111 __METHOD__, $ticket, [
'timeout' => 3 ]
119 $dbw->unlock( $lockKey, __METHOD__ );
123 $activeUserDays = MediaWikiServices::getInstance()->getMainConfig()->get(
124 MainConfigNames::ActiveUserDays );
127 $days = $activeUserDays;
129 $window = $activeUserDays * 86400;
132 $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
133 $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
135 $lockKey = $dbw->getDomainID() .
'-activeusers';
136 if ( !$dbw->lock( $lockKey, __METHOD__, 0 ) ) {
143 $dbw->setSessionOptions( [
'connTimeout' => 900 ] );
147 $cTime = $dbw->selectField(
'querycache_info',
149 [
'qci_type' =>
'activeusers' ],
152 $cTimeUnix = $cTime ? (int)
wfTimestamp( TS_UNIX, $cTime ) : 1;
157 $sTimestamp = max( $cTimeUnix, $nowUnix - $days * 86400 );
158 $eTimestamp = min( $sTimestamp + $window, $nowUnix );
162 [
'recentchanges',
'actor' ],
165 'lastedittime' =>
'MAX(rc_timestamp)'
168 'actor_user IS NOT NULL',
170 'rc_log_type IS NULL OR rc_log_type != ' . $dbw->addQuotes(
'newusers' ),
171 'rc_timestamp >= ' . $dbw->addQuotes( $dbw->timestamp( $sTimestamp ) ),
172 'rc_timestamp <= ' . $dbw->addQuotes( $dbw->timestamp( $eTimestamp ) )
176 'GROUP BY' =>
'actor_name',
180 'actor' => [
'JOIN',
'actor_id=rc_actor' ]
184 foreach (
$res as $row ) {
185 $names[$row->actor_name] = $row->lastedittime;
189 if ( count( $names ) ) {
190 $res = $dbw->select(
'querycachetwo',
191 [
'user_name' =>
'qcc_title' ],
193 'qcc_type' =>
'activeusers',
195 'qcc_title' => array_map(
'strval', array_keys( $names ) ),
196 'qcc_value >= ' . $dbw->addQuotes( $nowUnix - $days * 86400 ),
202 foreach (
$res as $row ) {
203 unset( $names[$row->user_name] );
208 if ( count( $names ) ) {
210 foreach ( $names as $name => $lastEditTime ) {
212 'qcc_type' =>
'activeusers',
214 'qcc_title' => $name,
215 'qcc_value' => (int)
wfTimestamp( TS_UNIX, $lastEditTime ),
216 'qcc_namespacetwo' => 0,
220 foreach ( array_chunk( $newRows, 500 ) as $rowBatch ) {
221 $dbw->insert(
'querycachetwo', $rowBatch, __METHOD__ );
222 $factory->commitAndWaitForReplication( __METHOD__, $ticket );
228 $asOfTimestamp = min( $eTimestamp, (
int)$dbw->trxTimestamp() );
234 [
'qci_type' =>
'activeusers',
235 'qci_timestamp' => $dbw->timestamp( $asOfTimestamp ) ],
240 $dbw->delete(
'querycachetwo',
242 'qcc_type' =>
'activeusers',
243 'qcc_value < ' . $dbw->addQuotes( $nowUnix - $days * 86400 )
248 if ( !MediaWikiServices::getInstance()->getMainConfig()->
get( MainConfigNames::MiserMode ) ) {
249 SiteStatsUpdate::cacheUpdate( $dbw );
252 $dbw->unlock( $lockKey, __METHOD__ );