Merge "Bound the cache size of numberofWatchingusers()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 4 Sep 2014 20:03:11 +0000 (20:03 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 4 Sep 2014 20:03:11 +0000 (20:03 +0000)
1  2 
includes/changes/ChangesList.php

@@@ -36,6 -36,9 +36,9 @@@ class ChangesList extends ContextSourc
        protected $rclistOpen;
        protected $rcMoveIndex;
  
+       /** @var MapCacheLRU */
+       protected $watchingCache;
        /**
         * Changeslist constructor
         *
@@@ -50,6 -53,7 +53,7 @@@
                        $this->skin = $obj;
                }
                $this->preCacheMessages();
+               $this->watchingCache = new MapCacheLRU( 50 );
        }
  
        /**
         * @return string
         */
        public function recentChangesFlags( $flags, $nothing = '&#160;' ) {
 -              global $wgRecentChangesFlags;
                $f = '';
 -              foreach ( array_keys( $wgRecentChangesFlags ) as $flag ) {
 +              foreach ( array_keys( $this->getConfig()->get( 'RecentChangesFlags' ) ) as $flag ) {
                        $f .= isset( $flags[$flag] ) && $flags[$flag]
                                ? self::flag( $flag )
                                : $nothing;
         * @return string
         */
        public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
 -              global $wgRCChangedSizeThreshold, $wgMiserMode;
 -
                if ( !$context ) {
                        $context = RequestContext::getMain();
                }
                $szdiff = $new - $old;
  
                $lang = $context->getLanguage();
 +              $config = $context->getConfig();
                $code = $lang->getCode();
                static $fastCharDiff = array();
                if ( !isset( $fastCharDiff[$code] ) ) {
 -                      $fastCharDiff[$code] = $wgMiserMode || $context->msg( 'rc-change-size' )->plain() === '$1';
 +                      $fastCharDiff[$code] = $config->get( 'MiserMode' ) || $context->msg( 'rc-change-size' )->plain() === '$1';
                }
  
                $formattedSize = $lang->formatNum( $szdiff );
                        $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
                }
  
 -              if ( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
 +              if ( abs( $szdiff ) > abs( $config->get( 'RCChangedSizeThreshold' ) ) ) {
                        $tag = 'strong';
                } else {
                        $tag = 'span';
         * @return string
         */
        protected function numberofWatchingusers( $count ) {
-               static $cache = array();
+               $cache = $this->watchingCache;
                if ( $count > 0 ) {
-                       if ( !isset( $cache[$count] ) ) {
-                               $cache[$count] = $this->msg( 'number_of_watching_users_RCview' )
-                                       ->numParams( $count )->escaped();
+                       if ( !$cache->has( $count ) ) {
+                               $cache->set( $count, $this->msg( 'number_of_watching_users_RCview' )
+                                       ->numParams( $count )->escaped() );
                        }
  
-                       return $cache[$count];
+                       return $cache->get( $count );
                } else {
                        return '';
                }