From a607f11f9446ae06e067334877c6a47d9bce1bcb Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 24 Sep 2015 21:59:25 -0700 Subject: [PATCH] Made wfIsBadImage() use APC * Article 404s spend are large chunk of their time there and the method is also hit on page save Change-Id: I26043f596195a8fe322bc154bf375a6c5d39c968 --- includes/GlobalFunctions.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 404d2cf1bb..8f70120833 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -4072,8 +4072,6 @@ function wfUnpack( $format, $data, $length = false ) { * @return bool */ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) { - static $badImageCache = null; // based on bad_image_list msg - # Handle redirects $redirectTitle = RepoGroup::singleton()->checkRedirect( Title::makeTitle( NS_FILE, $name ) ); if ( $redirectTitle ) { @@ -4086,10 +4084,11 @@ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) { return $bad; } - $cacheable = ( $blacklist === null ); - if ( $cacheable && $badImageCache !== null ) { - $badImages = $badImageCache; - } else { // cache miss + $cache = ObjectCache::newAccelerator( 'hash' ); + $key = wfMemcKey( 'bad-image-list', ( $blacklist === null ) ? 'default' : md5( $blacklist ) ); + $badImages = $cache->get( $key ); + + if ( $badImages === false ) { // cache miss if ( $blacklist === null ) { $blacklist = wfMessage( 'bad_image_list' )->inContentLanguage()->plain(); // site list } @@ -4125,13 +4124,12 @@ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) { $badImages[$imageDBkey] = $exceptions; } } - if ( $cacheable ) { - $badImageCache = $badImages; - } + $cache->set( $key, $badImages, 60 ); } $contextKey = $contextTitle ? $contextTitle->getPrefixedDBkey() : false; $bad = isset( $badImages[$name] ) && !isset( $badImages[$name][$contextKey] ); + return $bad; } -- 2.20.1