Cache VCS commit id/date text on Special:Version
authorAlex Monk <krenair@gmail.com>
Sun, 17 Nov 2013 17:30:42 +0000 (17:30 +0000)
committerOri.livneh <ori@wikimedia.org>
Mon, 7 Apr 2014 18:53:56 +0000 (18:53 +0000)
So Special:Version works on beta.wmflabs.org again

Bug: 53335
Change-Id: I5a5b23a73974aba2322bf69f534e8aa8b60741db

includes/specials/SpecialVersion.php

index c8add01..5c3f509 100644 (file)
 class SpecialVersion extends SpecialPage {
        protected $firstExtOpened = false;
 
+       /**
+        * Stores the current rev id/SHA hash of MediaWiki core
+        */
+       protected $coreId = '';
+
        protected static $extensionTypes = false;
 
        protected static $viewvcUrls = array(
@@ -616,20 +621,43 @@ class SpecialVersion extends SpecialPage {
                }
 
                if ( isset( $extension['path'] ) ) {
-                       $extensionPath = dirname( $extension['path'] );
-                       $gitInfo = new GitInfo( $extensionPath );
-                       $vcsVersion = $gitInfo->getHeadSHA1();
-                       if ( $vcsVersion !== false ) {
-                               $vcsVersion = substr( $vcsVersion, 0, 7 );
-                               $vcsLink = $gitInfo->getHeadViewUrl();
-                               $vcsDate = $gitInfo->getHeadCommitDate();
-                       } else {
-                               $svnInfo = self::getSvnInfo( $extensionPath );
-                               if ( $svnInfo !== false ) {
-                                       $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
-                                       $vcsLink = isset( $svnInfo['viewvc-url'] ) ? $svnInfo['viewvc-url'] : '';
+                       global $IP;
+                       if ( $this->coreId == '' ) {
+                               wfDebug( 'Looking up core head id' );
+                               $coreHeadSHA1 = self::getGitHeadSha1( $IP );
+                               if ( $coreHeadSHA1 ) {
+                                       $this->coreId = $coreHeadSHA1;
+                               } else {
+                                       $svnInfo = self::getSvnInfo( $IP );
+                                       if ( $svnInfo !== false ) {
+                                               $this->coreId = $svnInfo['checkout-rev'];
+                                       }
                                }
                        }
+                       $cache = wfGetCache( CACHE_ANYTHING );
+                       $memcKey = wfMemcKey( 'specialversion-ext-version-text', $extension['path'], $this->coreId );
+                       list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
+
+                       if ( !$vcsVersion ) {
+                               wfDebug( "Getting VCS info for extension $extensionName" );
+                               $extensionPath = dirname( $extension['path'] );
+                               $gitInfo = new GitInfo( $extensionPath );
+                               $vcsVersion = $gitInfo->getHeadSHA1();
+                               if ( $vcsVersion !== false ) {
+                                       $vcsVersion = substr( $vcsVersion, 0, 7 );
+                                       $vcsLink = $gitInfo->getHeadViewUrl();
+                                       $vcsDate = $gitInfo->getHeadCommitDate();
+                               } else {
+                                       $svnInfo = self::getSvnInfo( $extensionPath );
+                                       if ( $svnInfo !== false ) {
+                                               $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
+                                               $vcsLink = isset( $svnInfo['viewvc-url'] ) ? $svnInfo['viewvc-url'] : '';
+                                       }
+                               }
+                               $cache->set( $memcKey, array( $vcsVersion, $vcsLink, $vcsDate ), 60 * 60 * 24 );
+                       } else {
+                               wfDebug( "Pulled VCS info for extension $extensionName from cache" );
+                       }
                }
 
                $versionString = Html::rawElement(