From: Kunal Mehta Date: Thu, 25 May 2017 07:46:48 +0000 (-0700) Subject: SiteStatsUpdate: Avoid deprecated wfMemcKey() X-Git-Tag: 1.31.0-rc.0~3126^2 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=72aaae7b0b2592c59a9ba22b482cc7721a8f1335;p=lhc%2Fweb%2Fwiklou.git SiteStatsUpdate: Avoid deprecated wfMemcKey() And the deprecated ObjectCache::getMainStashInstance() while we're at it. Change-Id: Iebd4e029c3ab6443403087d991bb263ef83b1ed8 --- diff --git a/includes/deferred/SiteStatsUpdate.php b/includes/deferred/SiteStatsUpdate.php index aefa7f5d54..8c38d8b0ca 100644 --- a/includes/deferred/SiteStatsUpdate.php +++ b/includes/deferred/SiteStatsUpdate.php @@ -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 @@ -207,12 +207,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 +223,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 +239,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 +247,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 +259,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 ); } } }