From: Aaron Schulz Date: Wed, 13 Mar 2019 18:14:19 +0000 (-0700) Subject: filebackend: change "profiler" parameter in FileBackend so it works again X-Git-Tag: 1.34.0-rc.0~2520^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=c25d8111bed4c07489537aa733366d60159cd606;p=lhc%2Fweb%2Fwiklou.git filebackend: change "profiler" parameter in FileBackend so it works again The Profiler::profileIn and Profiler::profileOut methods are just stubs. Use a callback to the Profile::scopedProfileIn method instead. Change-Id: I7b493c145357994f61faebfbe3f65d38d2e6da42 --- diff --git a/includes/filebackend/FileBackendGroup.php b/includes/filebackend/FileBackendGroup.php index cbf9bff93f..a09160827b 100644 --- a/includes/filebackend/FileBackendGroup.php +++ b/includes/filebackend/FileBackendGroup.php @@ -189,7 +189,9 @@ class FileBackendGroup { 'wanCache' => MediaWikiServices::getInstance()->getMainWANObjectCache(), 'srvCache' => ObjectCache::getLocalServerInstance( 'hash' ), 'logger' => LoggerFactory::getInstance( 'FileOperation' ), - 'profiler' => Profiler::instance() + 'profiler' => function ( $section ) { + return Profiler::instance()->scopedProfileIn( $section ); + } ]; $config['lockManager'] = LockManagerGroup::singleton( $config['wikiId'] )->get( $config['lockManager'] ); diff --git a/includes/libs/filebackend/FileBackend.php b/includes/libs/filebackend/FileBackend.php index a80b6d0c06..19373eaef9 100644 --- a/includes/libs/filebackend/FileBackend.php +++ b/includes/libs/filebackend/FileBackend.php @@ -114,7 +114,7 @@ abstract class FileBackend implements LoggerAwareInterface { protected $fileJournal; /** @var LoggerInterface */ protected $logger; - /** @var object|string Class name or object With profileIn/profileOut methods */ + /** @var callable|null */ protected $profiler; /** @var callable */ @@ -156,7 +156,8 @@ abstract class FileBackend implements LoggerAwareInterface { * - obResetFunc : alternative callback to clear the output buffer * - streamMimeFunc : alternative method to determine the content type from the path * - logger : Optional PSR logger object. - * - profiler : Optional class name or object With profileIn/profileOut methods. + * - profiler : Optional callback that takes a section name argument and returns + * a ScopedCallback instance that ends the profile section in its destructor. * @throws InvalidArgumentException */ public function __construct( array $config ) { @@ -187,6 +188,9 @@ abstract class FileBackend implements LoggerAwareInterface { $this->statusWrapper = $config['statusWrapper'] ?? null; $this->profiler = $config['profiler'] ?? null; + if ( !is_callable( $this->profiler ) ) { + $this->profiler = null; + } $this->logger = $config['logger'] ?? new \Psr\Log\NullLogger(); $this->statusWrapper = $config['statusWrapper'] ?? null; $this->tmpDirectory = $config['tmpDirectory'] ?? null; @@ -1599,12 +1603,7 @@ abstract class FileBackend implements LoggerAwareInterface { * @return ScopedCallback|null */ protected function scopedProfileSection( $section ) { - if ( $this->profiler ) { - call_user_func( [ $this->profiler, 'profileIn' ], $section ); - return new ScopedCallback( [ $this->profiler, 'profileOut' ], [ $section ] ); - } - - return null; + return $this->profiler ? ( $this->profiler )( $section ) : null; } protected function resetOutputBuffer() {