X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderModule.php;h=ca311d9de56e7bbd1ebd9d0e54a6ad7a01291088;hp=b39262527c9f8a8e60a11557b839fb986ab30f0d;hb=77c7f6391fcd1ef2f9137910fcbcd353139e9ebb;hpb=dc24eba870a2f218583b82aa01a11e3129477d44 diff --git a/includes/resourceloader/ResourceLoaderModule.php b/includes/resourceloader/ResourceLoaderModule.php index b39262527c..ca311d9de5 100644 --- a/includes/resourceloader/ResourceLoaderModule.php +++ b/includes/resourceloader/ResourceLoaderModule.php @@ -182,7 +182,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { /** * Takes named templates by the module and returns an array mapping. * - * @return array of templates mapping template alias to content + * @return string[] Array of templates mapping template alias to content */ public function getTemplates() { // Stub, override expected. @@ -476,44 +476,52 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { $localFileRefs = array_values( array_unique( $localFileRefs ) ); sort( $localFileRefs ); $localPaths = self::getRelativePaths( $localFileRefs ); - $storedPaths = self::getRelativePaths( $this->getFileDependencies( $context ) ); - // If the list has been modified since last time we cached it, update the cache - if ( $localPaths !== $storedPaths ) { - $vary = $context->getSkin() . '|' . $context->getLanguage(); - $cache = ObjectCache::getLocalClusterInstance(); - $key = $cache->makeKey( __METHOD__, $this->getName(), $vary ); - $scopeLock = $cache->getScopedLock( $key, 0 ); - if ( !$scopeLock ) { - return; // T124649; avoid write slams - } - // No needless escaping as this isn't HTML output. - // Only stored in the database and parsed in PHP. - $deps = json_encode( $localPaths, JSON_UNESCAPED_SLASHES ); - $dbw = wfGetDB( DB_MASTER ); - $dbw->upsert( 'module_deps', - [ - 'md_module' => $this->getName(), - 'md_skin' => $vary, - 'md_deps' => $deps, - ], - [ 'md_module', 'md_skin' ], - [ - 'md_deps' => $deps, - ] - ); + if ( $localPaths === $storedPaths ) { + // Unchanged. Avoid needless database query (especially master conn!). + return; + } - if ( $dbw->trxLevel() ) { - $dbw->onTransactionResolution( - function () use ( &$scopeLock ) { - ScopedCallback::consume( $scopeLock ); // release after commit - }, - __METHOD__ - ); - } + // The file deps list has changed, we want to update it. + $vary = $context->getSkin() . '|' . $context->getLanguage(); + $cache = ObjectCache::getLocalClusterInstance(); + $key = $cache->makeKey( __METHOD__, $this->getName(), $vary ); + $scopeLock = $cache->getScopedLock( $key, 0 ); + if ( !$scopeLock ) { + // Another request appears to be doing this update already. + // Avoid write slams (T124649). + return; + } + + // No needless escaping as this isn't HTML output. + // Only stored in the database and parsed in PHP. + $deps = json_encode( $localPaths, JSON_UNESCAPED_SLASHES ); + $dbw = wfGetDB( DB_MASTER ); + $dbw->upsert( 'module_deps', + [ + 'md_module' => $this->getName(), + 'md_skin' => $vary, + 'md_deps' => $deps, + ], + [ 'md_module', 'md_skin' ], + [ + 'md_deps' => $deps, + ], + __METHOD__ + ); + + if ( $dbw->trxLevel() ) { + $dbw->onTransactionResolution( + function () use ( &$scopeLock ) { + ScopedCallback::consume( $scopeLock ); // release after commit + }, + __METHOD__ + ); } } catch ( Exception $e ) { + // Probably a DB failure. Either the read query from getFileDependencies(), + // or the write query above. wfDebugLog( 'resourceloader', __METHOD__ . ": failed to update DB: $e" ); } } @@ -734,7 +742,6 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { } $content['scripts'] = $scripts; - // Styles $styles = []; // Don't create empty stylesheets like [ '' => '' ] for modules // that don't *have* any stylesheets (T40024). @@ -944,7 +951,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { if ( !$this->getConfig()->get( 'ResourceLoaderValidateJS' ) ) { return $contents; } - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); return $cache->getWithSetCallback( $cache->makeGlobalKey( 'resourceloader',