Index: branches/RL2/extensions/Gadgets/Gadgets.hooks.php |
— | — | @@ -207,14 +207,23 @@ |
208 | 208 | * @param $defaultOptions Array of default preference keys and values |
209 | 209 | */ |
210 | 210 | 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 | + } |
217 | 224 | } |
218 | 225 | } |
| 226 | + |
| 227 | + $defaultOptions = $add + $defaultOptions; |
219 | 228 | return true; |
220 | 229 | } |
221 | 230 | |