Process cache tagUsageStatistics() to improve performance
authorAaron Schulz <aschulz@wikimedia.org>
Sun, 24 May 2015 07:59:49 +0000 (00:59 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Sun, 24 May 2015 07:59:49 +0000 (00:59 -0700)
Change-Id: I4a95c00d84c216ad08f30f0971877dfb728f86ff

includes/changetags/ChangeTags.php

index a730116..79763bd 100644 (file)
@@ -1177,9 +1177,15 @@ class ChangeTags {
         * @return array Array of string => int
         */
        public static function tagUsageStatistics() {
-               $fname = __METHOD__;
+               static $cachedStats = null;
 
-               return ObjectCache::getMainWANInstance()->getWithSetCallback(
+               // Process cache to avoid I/O and repeated regens during holdoff
+               if ( $cachedStats !== null ) {
+                       return $cachedStats;
+               }
+
+               $fname = __METHOD__;
+               $cachedStats = ObjectCache::getMainWANInstance()->getWithSetCallback(
                        wfMemcKey( 'change-tag-statistics' ),
                        function() use ( $fname ) {
                                $out = array();
@@ -1209,6 +1215,8 @@ class ChangeTags {
                        array( wfMemcKey( 'change-tag-statistics' ) ),
                        array( 'lockTSE' => INF )
                );
+
+               return $cachedStats;
        }
 
        /**