From e458290d7cd318016d706681c38b98f772b23fc3 Mon Sep 17 00:00:00 2001 From: Alex Monk Date: Sun, 17 Nov 2013 17:30:42 +0000 Subject: [PATCH] Cache VCS commit id/date text on Special:Version So Special:Version works on beta.wmflabs.org again Bug: 53335 Change-Id: I5a5b23a73974aba2322bf69f534e8aa8b60741db --- includes/specials/SpecialVersion.php | 52 +++++++++++++++++++++------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/includes/specials/SpecialVersion.php b/includes/specials/SpecialVersion.php index c8add014a6..5c3f509895 100644 --- a/includes/specials/SpecialVersion.php +++ b/includes/specials/SpecialVersion.php @@ -31,6 +31,11 @@ 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( -- 2.20.1