From 305a314c7ffe420ce42b4cf2829044b2b8e8ae67 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 12 Apr 2016 16:21:52 -0700 Subject: [PATCH] Convert File::getDescriptionText() to getWithSetCallback() Change-Id: Ia27d6fc851598162367ad6e749feb6d76f2569bc --- includes/filerepo/file/File.php | 45 +++++++++++++++------------------ 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 7e007937c3..c037516568 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -2046,34 +2046,29 @@ abstract class File implements IDBAccessObject { $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() ); if ( $renderUrl ) { $cache = ObjectCache::getMainWANInstance(); + $key = $this->repo->getLocalCacheKey( + 'RemoteFileDescription', + 'url', + $lang->getCode(), + $this->getName() + ); - $key = null; - if ( $this->repo->descriptionCacheExpiry > 0 ) { - wfDebug( "Attempting to get the description from cache..." ); - $key = $this->repo->getLocalCacheKey( - 'RemoteFileDescription', - 'url', - $lang->getCode(), - $this->getName() - ); - $obj = $cache->get( $key ); - if ( $obj ) { - wfDebug( "success!\n" ); - - return $obj; - } - wfDebug( "miss\n" ); - } - wfDebug( "Fetching shared description from $renderUrl\n" ); - $res = Http::get( $renderUrl, [], __METHOD__ ); - if ( $res && $key ) { - $cache->set( $key, $res, $this->repo->descriptionCacheExpiry ); - } + return $cache->getWithSetCallback( + $key, + $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE, + function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl ) { + wfDebug( "Fetching shared description from $renderUrl\n" ); + $res = Http::get( $renderUrl, [], __METHOD__ ); + if ( !$res ) { + $ttl = WANObjectCache::TTL_UNCACHEABLE; + } - return $res; - } else { - return false; + return $res; + } + ); } + + return false; } /** -- 2.20.1