Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/249352

Change subject: Convert buildSidebar() to using getWithSetCallback()
......................................................................

Convert buildSidebar() to using getWithSetCallback()

Change-Id: Id9a27ba2bbd3aceee26bf35844d1c970dbb32d47
---
M includes/cache/MessageCache.php
M includes/skins/Skin.php
2 files changed, 15 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/52/249352/1

diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php
index 09e9077..bcfa792 100644
--- a/includes/cache/MessageCache.php
+++ b/includes/cache/MessageCache.php
@@ -574,7 +574,7 @@
 
                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 12ebb54..0cb9783 100644
--- a/includes/skins/Skin.php
+++ b/includes/skins/Skin.php
@@ -1226,28 +1226,24 @@
                global $wgEnableSidebarCache, $wgSidebarCacheExpiry;
 
                $cache = ObjectCache::getMainWANInstance();
-               $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
 
-               if ( $wgEnableSidebarCache ) {
-                       $cachedsidebar = $cache->get( $key );
-                       if ( $cachedsidebar ) {
-                               Hooks::run( 'SidebarBeforeOutput', array( 
$this, &$cachedsidebar ) );
+               $that = $this;
+               $sidebar = $cache->getWithSetCallback(
+                       $cache->makeKey( 'sidebar', 
$this->getLanguage()->getCode() ),
+                       $wgEnableSidebarCache ? $wgSidebarCacheExpiry : 
$cache::TTL_UNCACHEABLE,
+                       function () use ( $that ) {
+                               $bar = array();
+                               $that->addToSidebar( $bar, 'sidebar' );
+                               Hooks::run( 'SkinBuildSidebar', array( $that, 
&$bar ) );
 
-                               return $cachedsidebar;
+                               return $bar;
                        }
-               }
+               );
 
-               $bar = array();
-               $this->addToSidebar( $bar, 'sidebar' );
+               // Apply post-processing to the cached value
+               Hooks::run( 'SidebarBeforeOutput', array( $this, &$sidebar ) );
 
-               Hooks::run( 'SkinBuildSidebar', array( $this, &$bar ) );
-               if ( $wgEnableSidebarCache ) {
-                       $cache->set( $key, $bar, $wgSidebarCacheExpiry );
-               }
-
-               Hooks::run( 'SidebarBeforeOutput', array( $this, &$bar ) );
-
-               return $bar;
+               return $sidebar;
        }
 
        /**
@@ -1259,7 +1255,7 @@
         * @param array $bar
         * @param string $message
         */
-       function addToSidebar( &$bar, $message ) {
+       public function addToSidebar( &$bar, $message ) {
                $this->addToSidebarPlain( $bar, wfMessage( $message 
)->inContentLanguage()->plain() );
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/249352
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id9a27ba2bbd3aceee26bf35844d1c970dbb32d47
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to