From: Max Semenik Date: Fri, 2 Jan 2015 08:47:26 +0000 (-0800) Subject: Don't call localisation functions when initializing pageset X-Git-Tag: 1.31.0-rc.0~12739^2 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=fc505d4fa538c933cd1e2637454bbd2ccb8bcaae;p=lhc%2Fweb%2Fwiklou.git Don't call localisation functions when initializing pageset Language::commaList() gets called even though in 99% of cases it's not description that's needed but other parameter information, resulting in 0.6% of overall cluster CPU time being wasted per https://performance.wikimedia.org/xenon/svgs/daily/2015-01-02.svgz Change-Id: Ic77e4a03d1bbd1aa5f86dc250d9f903d7eb25618 --- diff --git a/autoload.php b/autoload.php index a1ac905569..f2b0554683 100644 --- a/autoload.php +++ b/autoload.php @@ -291,6 +291,7 @@ $wgAutoloadLocalClasses = array( 'DateFormatter' => __DIR__ . '/includes/parser/DateFormatter.php', 'DeadendPagesPage' => __DIR__ . '/includes/specials/SpecialDeadendpages.php', 'DeferrableUpdate' => __DIR__ . '/includes/deferred/DeferredUpdates.php', + 'DeferredStringifier' => __DIR__ . '/includes/DeferredStringifier.php', 'DeferredUpdates' => __DIR__ . '/includes/deferred/DeferredUpdates.php', 'DeleteAction' => __DIR__ . '/includes/actions/DeleteAction.php', 'DeleteArchivedFiles' => __DIR__ . '/maintenance/deleteArchivedFiles.php', diff --git a/includes/DeferredStringifier.php b/includes/DeferredStringifier.php new file mode 100644 index 0000000000..bd32949833 --- /dev/null +++ b/includes/DeferredStringifier.php @@ -0,0 +1,55 @@ +params = func_get_args(); + array_shift( $this->params ); + $this->callback = $callback; + } + + /** + * Returns a string generated by callback + * + * @return string + */ + public function __toString() { + if ( $this->result === null ) { + $this->result = call_user_func_array( $this->callback, $this->params ); + } + return $this->result; + } +} diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 1417ef7833..c7147cb39a 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -1326,7 +1326,13 @@ class ApiPageSet extends ApiBase { ApiBase::PARAM_DFLT => false, ApiBase::PARAM_HELP_MSG => array( 'api-pageset-param-converttitles', - $this->getLanguage()->commaList( LanguageConverter::$languagesWithVariants ), + new DeferredStringifier( + function ( IContextSource $context ) { + return $context->getLanguage() + ->commaList( LanguageConverter::$languagesWithVariants ); + }, + $this + ) ), ), );