From: Aaron Schulz Date: Wed, 28 Oct 2015 05:25:36 +0000 (-0700) Subject: Convert buildSidebar() to using getWithSetCallback() X-Git-Tag: 1.31.0-rc.0~9184^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=141197dd27424d10323a7ec1bc64159c832fedd2;p=lhc%2Fweb%2Fwiklou.git Convert buildSidebar() to using getWithSetCallback() Change-Id: Id9a27ba2bbd3aceee26bf35844d1c970dbb32d47 --- diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php index 09e9077468..bcfa792a37 100644 --- a/includes/cache/MessageCache.php +++ b/includes/cache/MessageCache.php @@ -574,7 +574,7 @@ class MessageCache { foreach ( $codes as $code ) { $sidebarKey = wfMemcKey( 'sidebar', $code ); - $this->wanCache->delete( $sidebarKey, 5 ); + $this->wanCache->delete( $sidebarKey ); } // Update the message in the message blob store diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php index 12ebb5432f..08e4885b94 100644 --- a/includes/skins/Skin.php +++ b/includes/skins/Skin.php @@ -1225,29 +1225,31 @@ abstract class Skin extends ContextSource { function buildSidebar() { global $wgEnableSidebarCache, $wgSidebarCacheExpiry; - $cache = ObjectCache::getMainWANInstance(); - $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() ); + $that = $this; + $callback = function () use ( $that ) { + $bar = array(); + $that->addToSidebar( $bar, 'sidebar' ); + Hooks::run( 'SkinBuildSidebar', array( $that, &$bar ) ); - if ( $wgEnableSidebarCache ) { - $cachedsidebar = $cache->get( $key ); - if ( $cachedsidebar ) { - Hooks::run( 'SidebarBeforeOutput', array( $this, &$cachedsidebar ) ); - - return $cachedsidebar; - } - } + return $bar; + }; - $bar = array(); - $this->addToSidebar( $bar, 'sidebar' ); - - Hooks::run( 'SkinBuildSidebar', array( $this, &$bar ) ); if ( $wgEnableSidebarCache ) { - $cache->set( $key, $bar, $wgSidebarCacheExpiry ); + $cache = ObjectCache::getMainWANInstance(); + $sidebar = $cache->getWithSetCallback( + $cache->makeKey( 'sidebar', $this->getLanguage()->getCode() ), + $wgSidebarCacheExpiry, + $callback, + array( 'lockTSE' => 30 ) + ); + } else { + $sidebar = $callback(); } - Hooks::run( 'SidebarBeforeOutput', array( $this, &$bar ) ); + // Apply post-processing to the cached value + Hooks::run( 'SidebarBeforeOutput', array( $this, &$sidebar ) ); - return $bar; + return $sidebar; } /** @@ -1259,7 +1261,7 @@ abstract class Skin extends ContextSource { * @param array $bar * @param string $message */ - function addToSidebar( &$bar, $message ) { + public function addToSidebar( &$bar, $message ) { $this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() ); }