Merge "OutputPage: Reduce getTitleInfo() calls (improve preloading)"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 20 Oct 2016 22:18:38 +0000 (22:18 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 20 Oct 2016 22:18:38 +0000 (22:18 +0000)
1  2 
includes/OutputPage.php

diff --combined includes/OutputPage.php
@@@ -2392,14 -2392,10 +2392,14 @@@ class OutputPage extends ContextSource 
        /**
         * Output a standard permission error page
         *
 -       * @param array $errors Error message keys
 +       * @param array $errors Error message keys or [key, param...] arrays
         * @param string $action Action that was denied or null if unknown
         */
        public function showPermissionsErrorPage( array $errors, $action = null ) {
 +              foreach ( $errors as $key => $error ) {
 +                      $errors[$key] = (array)$error;
 +              }
 +
                // For some action (read, edit, create and upload), display a "login to do this action"
                // error if all of the following conditions are met:
                // 1. the user is not logged in
                        $exemptStates = [];
                        $moduleStyles = $this->getModuleStyles( /*filter*/ true );
  
-                       // Batch preload getTitleInfo for isKnownEmpty() calls below
-                       $exemptModules = array_filter( $moduleStyles,
-                               function ( $name ) use ( $rl, &$exemptGroups ) {
-                                       $module = $rl->getModule( $name );
-                                       return $module && isset( $exemptGroups[ $module->getGroup() ] );
-                               }
-                       );
-                       ResourceLoaderWikiModule::preloadTitleInfo(
-                               $context, wfGetDB( DB_REPLICA ), $exemptModules );
+                       // Preload getTitleInfo for isKnownEmpty calls below and in ResourceLoaderClientHtml
+                       // Separate user-specific batch for improved cache-hit ratio.
+                       $userBatch = [ 'user.styles', 'user' ];
+                       $siteBatch = array_diff( $moduleStyles, $userBatch );
+                       $dbr = wfGetDB( DB_REPLICA );
+                       ResourceLoaderWikiModule::preloadTitleInfo( $context, $dbr, $siteBatch );
+                       ResourceLoaderWikiModule::preloadTitleInfo( $context, $dbr, $userBatch );
  
                        // Filter out modules handled by buildExemptModules()
                        $moduleStyles = array_filter( $moduleStyles,