Merge "Add attributes parameter to ShowSearchHitTitle"
[lhc/web/wiklou.git] / includes / deferred / SiteStatsUpdate.php
index aefa7f5..44876a6 100644 (file)
@@ -94,7 +94,7 @@ class SiteStatsUpdate implements DeferrableUpdate, MergeableUpdate {
                global $wgSiteStatsAsyncFactor;
 
                $dbw = wfGetDB( DB_MASTER );
-               $lockKey = wfMemcKey( 'site_stats' ); // prepend wiki ID
+               $lockKey = wfWikiID() . ':site_stats'; // prepend wiki ID
                $pd = [];
                if ( $wgSiteStatsAsyncFactor ) {
                        // Lock the table so we don't have double DB/memcached updates
@@ -149,6 +149,7 @@ class SiteStatsUpdate implements DeferrableUpdate, MergeableUpdate {
                        'recentchanges',
                        'COUNT( DISTINCT rc_user_text )',
                        [
+                               'rc_type != ' . $dbr->addQuotes( RC_EXTERNAL ), // Exclude external (Wikidata)
                                'rc_user != 0',
                                'rc_bot' => 0,
                                'rc_log_type != ' . $dbr->addQuotes( 'newusers' ) . ' OR rc_log_type IS NULL',
@@ -189,7 +190,7 @@ class SiteStatsUpdate implements DeferrableUpdate, MergeableUpdate {
        }
 
        /**
-        * @param string $sql
+        * @param string &$sql
         * @param string $field
         * @param int $delta
         */
@@ -207,12 +208,13 @@ class SiteStatsUpdate implements DeferrableUpdate, MergeableUpdate {
        }
 
        /**
+        * @param BagOStuff $cache
         * @param string $type
         * @param string $sign ('+' or '-')
         * @return string
         */
-       private function getTypeCacheKey( $type, $sign ) {
-               return wfMemcKey( 'sitestatsupdate', 'pendingdelta', $type, $sign );
+       private function getTypeCacheKey( BagOStuff $cache, $type, $sign ) {
+               return $cache->makeKey( 'sitestatsupdate', 'pendingdelta', $type, $sign );
        }
 
        /**
@@ -222,11 +224,11 @@ class SiteStatsUpdate implements DeferrableUpdate, MergeableUpdate {
         * @param int $delta Delta (positive or negative)
         */
        protected function adjustPending( $type, $delta ) {
-               $cache = ObjectCache::getMainStashInstance();
+               $cache = MediaWikiServices::getInstance()->getMainObjectStash();
                if ( $delta < 0 ) { // decrement
-                       $key = $this->getTypeCacheKey( $type, '-' );
+                       $key = $this->getTypeCacheKey( $cache, $type, '-' );
                } else { // increment
-                       $key = $this->getTypeCacheKey( $type, '+' );
+                       $key = $this->getTypeCacheKey( $cache, $type, '+' );
                }
 
                $magnitude = abs( $delta );
@@ -238,7 +240,7 @@ class SiteStatsUpdate implements DeferrableUpdate, MergeableUpdate {
         * @return array Positive and negative deltas for each type
         */
        protected function getPendingDeltas() {
-               $cache = ObjectCache::getMainStashInstance();
+               $cache = MediaWikiServices::getInstance()->getMainObjectStash();
 
                $pending = [];
                foreach ( [ 'ss_total_edits',
@@ -246,8 +248,8 @@ class SiteStatsUpdate implements DeferrableUpdate, MergeableUpdate {
                ) {
                        // Get pending increments and pending decrements
                        $flg = BagOStuff::READ_LATEST;
-                       $pending[$type]['+'] = (int)$cache->get( $this->getTypeCacheKey( $type, '+' ), $flg );
-                       $pending[$type]['-'] = (int)$cache->get( $this->getTypeCacheKey( $type, '-' ), $flg );
+                       $pending[$type]['+'] = (int)$cache->get( $this->getTypeCacheKey( $cache, $type, '+' ), $flg );
+                       $pending[$type]['-'] = (int)$cache->get( $this->getTypeCacheKey( $cache, $type, '-' ), $flg );
                }
 
                return $pending;
@@ -258,12 +260,12 @@ class SiteStatsUpdate implements DeferrableUpdate, MergeableUpdate {
         * @param array $pd Result of getPendingDeltas(), used for DB update
         */
        protected function removePendingDeltas( array $pd ) {
-               $cache = ObjectCache::getMainStashInstance();
+               $cache = MediaWikiServices::getInstance()->getMainObjectStash();
 
                foreach ( $pd as $type => $deltas ) {
                        foreach ( $deltas as $sign => $magnitude ) {
                                // Lower the pending counter now that we applied these changes
-                               $cache->decr( $this->getTypeCacheKey( $type, $sign ), $magnitude );
+                               $cache->decr( $this->getTypeCacheKey( $cache, $type, $sign ), $magnitude );
                        }
                }
        }