r101497 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101496‎ | r101497 | r101498 >
Date:16:33, 1 November 2011
Author:catrope
Status:ok
Tags:
Comment:
[RL2] Per r101495, the UserGetDefaultOptions hook is called a LOT, so do some caching on our side
Modified paths:
  • /branches/RL2/extensions/Gadgets/Gadgets.hooks.php (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/Gadgets.hooks.php
@@ -207,14 +207,23 @@
208208 * @param $defaultOptions Array of default preference keys and values
209209 */
210210 public static function userGetDefaultOptions( &$defaultOptions ) {
211 - $repo = LocalGadgetRepo::singleton();
212 - $gadgetIds = $repo->getGadgetIds();
213 - foreach ( $gadgetIds as $gadgetId ) {
214 - $gadget = $repo->getGadget( $gadgetId );
215 - if ( $gadget->isEnabledByDefault() ) {
216 - $defaultOptions['gadget-' . $gadget->getId()] = 1;
 211+ // Cache the stuff we're adding to $defaultOptions
 212+ // This is done because this hook function is called dozens of times during a typical request
 213+ // but we only want to hit the repo backend once
 214+ static $add = null;
 215+ if ( $add === null ) {
 216+ $add = array();
 217+ $repo = LocalGadgetRepo::singleton();
 218+ $gadgetIds = $repo->getGadgetIds();
 219+ foreach ( $gadgetIds as $gadgetId ) {
 220+ $gadget = $repo->getGadget( $gadgetId );
 221+ if ( $gadget->isEnabledByDefault() ) {
 222+ $add['gadget-' . $gadget->getId()] = 1;
 223+ }
217224 }
218225 }
 226+
 227+ $defaultOptions = $add + $defaultOptions;
219228 return true;
220229 }
221230

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101495Revert r101488, breaks parser test. Add a comment explaining why there is no ...catrope16:25, 1 November 2011

Status & tagging log