76 $lockKey =
wfWikiID() .
':recentchanges-prune';
79 if ( !$dbw->lockIsFree( $lockKey, __METHOD__ )
80 || !$dbw->lock( $lockKey, __METHOD__, 1 )
85 $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
86 $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
91 $res = $dbw->select(
'recentchanges',
93 [
'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ],
97 foreach (
$res as $row ) {
98 $rcIds[] = $row->rc_id;
102 $dbw->delete(
'recentchanges', [
'rc_id' => $rcIds ], __METHOD__ );
103 Hooks::run(
'RecentChangesPurgeRows', [
$rows ] );
106 $factory->commitAndWaitForReplication(
107 __METHOD__, $ticket, [
'timeout' => 3 ]
116 $dbw->unlock( $lockKey, __METHOD__ );
130 $dbw->onTransactionIdle(
131 function () use ( $dbw, $days, $window ) {
132 $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
133 $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
135 $dbw->setSessionOptions( [
'connTimeout' => 900 ] );
137 $lockKey =
wfWikiID() .
'-activeusers';
138 if ( !$dbw->lockIsFree( $lockKey, __METHOD__ ) || !$dbw->lock( $lockKey, __METHOD__, 1 ) ) {
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 );
161 [
'rc_user_text',
'lastedittime' =>
'MAX(rc_timestamp)' ],
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' => [
'rc_user_text' ],
176 foreach (
$res as $row ) {
177 $names[$row->rc_user_text] = $row->lastedittime;
181 if ( count( $names ) ) {
182 $res = $dbw->select(
'querycachetwo',
183 [
'user_name' =>
'qcc_title' ],
185 'qcc_type' =>
'activeusers',
186 'qcc_namespace' => NS_USER,
187 'qcc_title' => array_keys( $names ),
188 'qcc_value >= ' . $dbw->addQuotes( $nowUnix - $days * 86400 ),
194 foreach (
$res as $row ) {
195 unset( $names[$row->user_name] );
200 if ( count( $names ) ) {
202 foreach ( $names as $name => $lastEditTime ) {
204 'qcc_type' =>
'activeusers',
206 'qcc_title' =>
$name,
207 'qcc_value' =>
wfTimestamp( TS_UNIX, $lastEditTime ),
208 'qcc_namespacetwo' => 0,
212 foreach ( array_chunk( $newRows, 500 ) as $rowBatch ) {
213 $dbw->insert(
'querycachetwo', $rowBatch, __METHOD__ );
214 $factory->commitAndWaitForReplication( __METHOD__, $ticket );
220 $asOfTimestamp = min( $eTimestamp, (
int)$dbw->trxTimestamp() );
223 $dbw->replace(
'querycache_info',
225 [
'qci_type' =>
'activeusers',
226 'qci_timestamp' => $dbw->timestamp( $asOfTimestamp ) ],
230 $dbw->unlock( $lockKey, __METHOD__ );
233 $dbw->delete(
'querycachetwo',
235 'qcc_type' =>
'activeusers',
236 'qcc_value < ' . $dbw->addQuotes( $nowUnix - $days * 86400 )