Merge "Http::getProxy() method to get proxy configuration"
[lhc/web/wiklou.git] / includes / jobqueue / jobs / RecentChangesUpdateJob.php
index e86d914..22afead 100644 (file)
@@ -42,7 +42,7 @@ class RecentChangesUpdateJob extends Job {
         */
        final public static function newPurgeJob() {
                return new self(
-                       SpecialPage::getTitleFor( 'Recentchanges' ), array( 'type' => 'purge' )
+                       SpecialPage::getTitleFor( 'Recentchanges' ), [ 'type' => 'purge' ]
                );
        }
 
@@ -52,7 +52,7 @@ class RecentChangesUpdateJob extends Job {
         */
        final public static function newCacheUpdateJob() {
                return new self(
-                       SpecialPage::getTitleFor( 'Recentchanges' ), array( 'type' => 'cacheUpdate' )
+                       SpecialPage::getTitleFor( 'Recentchanges' ), [ 'type' => 'cacheUpdate' ]
                );
        }
 
@@ -75,28 +75,32 @@ class RecentChangesUpdateJob extends Job {
                $lockKey = wfWikiID() . ':recentchanges-prune';
 
                $dbw = wfGetDB( DB_MASTER );
-               if ( !$dbw->lock( $lockKey, __METHOD__, 1 ) ) {
+               if ( !$dbw->lockIsFree( $lockKey, __METHOD__ )
+                       || !$dbw->lock( $lockKey, __METHOD__, 1 )
+               ) {
                        return; // already in progress
                }
-               $batchSize = 100; // Avoid slave lag
 
+               $batchSize = 100; // avoid slave lag
                $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
                do {
                        $rcIds = $dbw->selectFieldValues( 'recentchanges',
                                'rc_id',
-                               array( 'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ),
+                               [ 'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ],
                                __METHOD__,
-                               array( 'LIMIT' => $batchSize )
+                               [ 'LIMIT' => $batchSize ]
                        );
                        if ( $rcIds ) {
-                               $dbw->delete( 'recentchanges', array( 'rc_id' => $rcIds ), __METHOD__ );
+                               $dbw->delete( 'recentchanges', [ 'rc_id' => $rcIds ], __METHOD__ );
                        }
                        // Commit in chunks to avoid slave lag
                        $dbw->commit( __METHOD__, 'flush' );
 
                        if ( count( $rcIds ) === $batchSize ) {
                                // There might be more, so try waiting for slaves
-                               if ( !wfWaitForSlaves( null, false, false, /* $timeout = */ 3 ) ) {
+                               try {
+                                       wfGetLBFactory()->waitForReplication( [ 'timeout' => 3 ] );
+                               } catch ( DBReplicationWaitError $e ) {
                                        // Another job will continue anyway
                                        break;
                                }
@@ -119,18 +123,18 @@ class RecentChangesUpdateJob extends Job {
                // onTransactionIdle() will run immediately since there is no trx.
                $dbw->onTransactionIdle( function() use ( $dbw, $days, $window ) {
                        // Avoid disconnect/ping() cycle that makes locks fall off
-                       $dbw->setSessionOptions( array( 'connTimeout' => 900 ) );
+                       $dbw->setSessionOptions( [ 'connTimeout' => 900 ] );
 
                        $lockKey = wfWikiID() . '-activeusers';
                        if ( !$dbw->lock( $lockKey, __METHOD__, 1 ) ) {
-                               return false; // exclusive update (avoids duplicate entries)
+                               return; // exclusive update (avoids duplicate entries)
                        }
 
                        $nowUnix = time();
                        // Get the last-updated timestamp for the cache
                        $cTime = $dbw->selectField( 'querycache_info',
                                'qci_timestamp',
-                               array( 'qci_type' => 'activeusers' )
+                               [ 'qci_type' => 'activeusers' ]
                        );
                        $cTimeUnix = $cTime ? wfTimestamp( TS_UNIX, $cTime ) : 1;
 
@@ -142,43 +146,43 @@ class RecentChangesUpdateJob extends Job {
 
                        // Get all the users active since the last update
                        $res = $dbw->select(
-                               array( 'recentchanges' ),
-                               array( 'rc_user_text', 'lastedittime' => 'MAX(rc_timestamp)' ),
-                               array(
+                               [ 'recentchanges' ],
+                               [ 'rc_user_text', 'lastedittime' => 'MAX(rc_timestamp)' ],
+                               [
                                        'rc_user > 0', // actual accounts
                                        'rc_type != ' . $dbw->addQuotes( RC_EXTERNAL ), // no wikidata
                                        'rc_log_type IS NULL OR rc_log_type != ' . $dbw->addQuotes( 'newusers' ),
                                        'rc_timestamp >= ' . $dbw->addQuotes( $dbw->timestamp( $sTimestamp ) ),
                                        'rc_timestamp <= ' . $dbw->addQuotes( $dbw->timestamp( $eTimestamp ) )
-                               ),
+                               ],
                                __METHOD__,
-                               array(
-                                       'GROUP BY' => array( 'rc_user_text' ),
+                               [
+                                       'GROUP BY' => [ 'rc_user_text' ],
                                        'ORDER BY' => 'NULL' // avoid filesort
-                               )
+                               ]
                        );
-                       $names = array();
+                       $names = [];
                        foreach ( $res as $row ) {
                                $names[$row->rc_user_text] = $row->lastedittime;
                        }
 
                        // Rotate out users that have not edited in too long (according to old data set)
                        $dbw->delete( 'querycachetwo',
-                               array(
+                               [
                                        'qcc_type' => 'activeusers',
                                        'qcc_value < ' . $dbw->addQuotes( $nowUnix - $days * 86400 ) // TS_UNIX
-                               ),
+                               ],
                                __METHOD__
                        );
 
                        // Find which of the recently active users are already accounted for
                        if ( count( $names ) ) {
                                $res = $dbw->select( 'querycachetwo',
-                                       array( 'user_name' => 'qcc_title' ),
-                                       array(
+                                       [ 'user_name' => 'qcc_title' ],
+                                       [
                                                'qcc_type' => 'activeusers',
                                                'qcc_namespace' => NS_USER,
-                                               'qcc_title' => array_keys( $names ) ),
+                                               'qcc_title' => array_keys( $names ) ],
                                        __METHOD__
                                );
                                foreach ( $res as $row ) {
@@ -188,20 +192,20 @@ class RecentChangesUpdateJob extends Job {
 
                        // Insert the users that need to be added to the list
                        if ( count( $names ) ) {
-                               $newRows = array();
+                               $newRows = [];
                                foreach ( $names as $name => $lastEditTime ) {
-                                       $newRows[] = array(
+                                       $newRows[] = [
                                                'qcc_type' => 'activeusers',
                                                'qcc_namespace' => NS_USER,
                                                'qcc_title' => $name,
                                                'qcc_value' => wfTimestamp( TS_UNIX, $lastEditTime ),
                                                'qcc_namespacetwo' => 0, // unused
                                                'qcc_titletwo' => '' // unused
-                                       );
+                                       ];
                                }
                                foreach ( array_chunk( $newRows, 500 ) as $rowBatch ) {
                                        $dbw->insert( 'querycachetwo', $rowBatch, __METHOD__ );
-                                       wfWaitForSlaves();
+                                       wfGetLBFactory()->waitForReplication();
                                }
                        }
 
@@ -211,9 +215,9 @@ class RecentChangesUpdateJob extends Job {
 
                        // Touch the data freshness timestamp
                        $dbw->replace( 'querycache_info',
-                               array( 'qci_type' ),
-                               array( 'qci_type' => 'activeusers',
-                                       'qci_timestamp' => $dbw->timestamp( $asOfTimestamp ) ), // not always $now
+                               [ 'qci_type' ],
+                               [ 'qci_type' => 'activeusers',
+                                       'qci_timestamp' => $dbw->timestamp( $asOfTimestamp ) ], // not always $now
                                __METHOD__
                        );