r101495 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101494‎ | r101495 | r101496 >
Date:16:25, 1 November 2011
Author:catrope
Status:ok
Tags:
Comment:
Revert r101488, breaks parser test. Add a comment explaining why there is no caching currently being done, and document the fact that the hook is called a zillion times in hooks.txt
Modified paths:
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -2032,7 +2032,10 @@
20332033 &$rights: Array of rights, which may be added to.
20342034
20352035 'UserGetDefaultOptions': after fetching the core default, this hook is ran
2036 -right before returning the options to the caller.
 2036+right before returning the options to the caller. WARNING: this hook is
 2037+called for every call to User::getDefaultOptions(), which means it's
 2038+potentially called dozens or hundreds of times. You may want to cache
 2039+the results of non-trivial operations in your hook function for this reason.
20372040 &$defaultOptions: Array of preference keys and their default values.
20382041
20392042 'UserGetEmail': called when getting an user email address
Index: trunk/phase3/includes/User.php
@@ -1207,10 +1207,6 @@
12081208 */
12091209 public static function getDefaultOptions() {
12101210 global $wgNamespacesToBeSearchedDefault, $wgDefaultUserOptions, $wgContLang, $wgDefaultSkin;
1211 - static $defOpt = null;
1212 - if ( $defOpt !== null ) {
1213 - return $defOpt;
1214 - }
12151211
12161212 $defOpt = $wgDefaultUserOptions;
12171213 # default language setting
@@ -1222,6 +1218,12 @@
12231219 }
12241220 $defOpt['skin'] = $wgDefaultSkin;
12251221
 1222+ // FIXME: Ideally we'd cache the results of this function so the hook is only run once,
 1223+ // but that breaks the parser tests because they rely on being able to change $wgContLang
 1224+ // mid-request and see that change reflected in the return value of this function.
 1225+ // Which is insane and would never happen during normal MW operation, but is also not
 1226+ // likely to get fixed unless and until we context-ify everything.
 1227+ // See also https://www.mediawiki.org/wiki/Special:Code/MediaWiki/101488#c25275
12261228 wfRunHooks( 'UserGetDefaultOptions', array( &$defOpt ) );
12271229
12281230 return $defOpt;

Follow-up revisions

RevisionCommit summaryAuthorDate
r101497[RL2] Per r101495, the UserGetDefaultOptions hook is called a LOT, so do some...catrope16:33, 1 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101488Cache the result of User::getDefaultOptions(), so the UserGetDefaultOptions h...catrope15:55, 1 November 2011

Status & tagging log