77 $lockKey =
wfWikiID() .
':recentchanges-prune';
80 if ( !$dbw->lock( $lockKey, __METHOD__, 0 ) ) {
85 $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
86 $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
88 $rcQuery = RecentChange::getQueryInfo();
95 [
'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ],
100 foreach (
$res as $row ) {
101 $rcIds[] = $row->rc_id;
105 $dbw->delete(
'recentchanges', [
'rc_id' => $rcIds ], __METHOD__ );
106 Hooks::run(
'RecentChangesPurgeRows', [
$rows ] );
109 $factory->commitAndWaitForReplication(
110 __METHOD__, $ticket, [
'timeout' => 3 ]
119 $dbw->unlock( $lockKey, __METHOD__ );
131 $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
132 $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
134 $lockKey =
wfWikiID() .
'-activeusers';
135 if ( !$dbw->lock( $lockKey, __METHOD__, 0 ) ) {
142 $dbw->setSessionOptions( [
'connTimeout' => 900 ] );
146 $cTime = $dbw->selectField(
'querycache_info',
148 [
'qci_type' =>
'activeusers' ]
150 $cTimeUnix = $cTime ?
wfTimestamp( TS_UNIX, $cTime ) : 1;
155 $sTimestamp = max( $cTimeUnix, $nowUnix - $days * 86400 );
156 $eTimestamp = min( $sTimestamp + $window, $nowUnix );
159 $actorQuery = ActorMigration::newMigration()->getJoin(
'rc_user' );
161 [
'recentchanges' ] + $actorQuery[
'tables'],
163 'rc_user_text' => $actorQuery[
'fields'][
'rc_user_text'],
164 'lastedittime' =>
'MAX(rc_timestamp)'
167 $actorQuery[
'fields'][
'rc_user'] .
' > 0',
169 'rc_log_type IS NULL OR rc_log_type != ' . $dbw->addQuotes(
'newusers' ),
170 'rc_timestamp >= ' . $dbw->addQuotes( $dbw->timestamp( $sTimestamp ) ),
171 'rc_timestamp <= ' . $dbw->addQuotes( $dbw->timestamp( $eTimestamp ) )
175 'GROUP BY' => [
'rc_user_text' ],
181 foreach (
$res as $row ) {
182 $names[$row->rc_user_text] = $row->lastedittime;
186 if ( count( $names ) ) {
187 $res = $dbw->select(
'querycachetwo',
188 [
'user_name' =>
'qcc_title' ],
190 'qcc_type' =>
'activeusers',
191 'qcc_namespace' => NS_USER,
192 'qcc_title' => array_keys( $names ),
193 'qcc_value >= ' . $dbw->addQuotes( $nowUnix - $days * 86400 ),
199 foreach (
$res as $row ) {
200 unset( $names[$row->user_name] );
205 if ( count( $names ) ) {
207 foreach ( $names as $name => $lastEditTime ) {
209 'qcc_type' =>
'activeusers',
211 'qcc_title' =>
$name,
212 'qcc_value' =>
wfTimestamp( TS_UNIX, $lastEditTime ),
213 'qcc_namespacetwo' => 0,
217 foreach ( array_chunk( $newRows, 500 ) as $rowBatch ) {
218 $dbw->insert(
'querycachetwo', $rowBatch, __METHOD__ );
219 $factory->commitAndWaitForReplication( __METHOD__, $ticket );
225 $asOfTimestamp = min( $eTimestamp, (
int)$dbw->trxTimestamp() );
228 $dbw->replace(
'querycache_info',
230 [
'qci_type' =>
'activeusers',
231 'qci_timestamp' => $dbw->timestamp( $asOfTimestamp ) ],
235 $dbw->unlock( $lockKey, __METHOD__ );
238 $dbw->delete(
'querycachetwo',
240 'qcc_type' =>
'activeusers',
241 'qcc_value < ' . $dbw->addQuotes( $nowUnix - $days * 86400 )