From: Timo Tijhof Date: Thu, 20 Oct 2016 21:43:57 +0000 (+0100) Subject: OutputPage: Reduce getTitleInfo() calls (improve preloading) X-Git-Tag: 1.31.0-rc.0~5056^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/%7B%7B%20url_for%28%27admin_users%27%29%20%7D%7D?a=commitdiff_plain;h=458d37f205c1160bfd0225384277b66cacef12fe;p=lhc%2Fweb%2Fwiklou.git OutputPage: Reduce getTitleInfo() calls (improve preloading) * Remove filter between $moduleStyles and preloadTitleInfo(). Previously, this was filtering out wiki modules created by gadgets and extensions. Still causing a couple of direct queries from getTitleInfo(). * Store __METHOD__ in $fname outside getWithSetCallback. This way queries are logged as either getTitleInfo or preloadTitleInfo. This regressed in 0852a000a5, after which the latter was logged as "::{closure}". Change-Id: I454e43f43f8ad3270b86f4cfdbd68192c305cc07 --- diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 50f9eb91fb..8e34a5a9eb 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2688,15 +2688,13 @@ class OutputPage extends ContextSource { $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, diff --git a/includes/resourceloader/ResourceLoaderWikiModule.php b/includes/resourceloader/ResourceLoaderWikiModule.php index 9c3b41cf90..3deeb84481 100644 --- a/includes/resourceloader/ResourceLoaderWikiModule.php +++ b/includes/resourceloader/ResourceLoaderWikiModule.php @@ -360,21 +360,22 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { } } - $allPageNames = array_keys( $allPages ); - sort( $allPageNames ); - $hash = sha1( implode( '|', $allPageNames ) ); + $pageNames = array_keys( $allPages ); + sort( $pageNames ); + $hash = sha1( implode( '|', $pageNames ) ); // Avoid Zend bug where "static::" does not apply LSB in the closure $func = [ static::class, 'fetchTitleInfo' ]; + $fname = __METHOD__; $cache = ObjectCache::getMainWANInstance(); $allInfo = $cache->getWithSetCallback( $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getWikiID(), $hash ), $cache::TTL_HOUR, - function ( $curValue, &$ttl, array &$setOpts ) use ( $func, $allPageNames, $db ) { + function ( $curVal, &$ttl, array &$setOpts ) use ( $func, $pageNames, $db, $fname ) { $setOpts += Database::getCacheSetOptions( $db ); - return call_user_func( $func, $db, $allPageNames, __METHOD__ ); + return call_user_func( $func, $db, $pageNames, $fname ); }, [ 'checkKeys' => [ $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getWikiID() ) ] ] );