From 2f401c66aa5e57419aa0884fe602de006edf1e60 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 26 Nov 2019 20:33:10 +0100 Subject: [PATCH] LocalisationCache: Don't instantiate ResourceLoader When clearing the LocalisationCache, avoid instantiating a ResourceLoader instance. Doing so introduces a circular dependency among service instances. This patch introduces a static method for clearing the MessageBlobStore without the need for a ResoruceLoader instance. Bug: T231866 Change-Id: I404e64713fee6a534ba014981cef78af0b91f2aa (cherry picked from commit 41415deda4c66ba52194c4df51c54c367f1f10b9) --- includes/ServiceWiring.php | 5 ++++- includes/resourceloader/MessageBlobStore.php | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 626c14fc46..a106157130 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -319,7 +319,10 @@ return [ $store, $logger, [ function () use ( $services ) { - $services->getResourceLoader()->getMessageBlobStore()->clear(); + // NOTE: Make sure we use the same cache object that is assigned in the + // constructor of the MessageBlobStore class used by ResourceLoader. + // T231866: Avoid circular dependency via ResourceLoader. + MessageBlobStore::clearGlobalCacheEntry( $services->getMainWANObjectCache() ); } ], $services->getLanguageNameUtils() ); diff --git a/includes/resourceloader/MessageBlobStore.php b/includes/resourceloader/MessageBlobStore.php index b4f0b7c25b..29dc866ecf 100644 --- a/includes/resourceloader/MessageBlobStore.php +++ b/includes/resourceloader/MessageBlobStore.php @@ -57,6 +57,10 @@ class MessageBlobStore implements LoggerAwareInterface { public function __construct( ResourceLoader $rl, LoggerInterface $logger = null ) { $this->resourceloader = $rl; $this->logger = $logger ?: new NullLogger(); + + // NOTE: when changing this assignment, make sure the code in the instantiator for + // LocalisationCache which calls MessageBlobStore::clearGlobalCacheEntry() uses the + // same cache object. $this->wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache(); } @@ -169,10 +173,19 @@ class MessageBlobStore implements LoggerAwareInterface { /** * Invalidate cache keys for all known modules. - * Called by LocalisationCache after cache is regenerated. */ public function clear() { - $cache = $this->wanCache; + self::clearGlobalCacheEntry( $this->wanCache ); + } + + /** + * Invalidate cache keys for all known modules. + * + * Called by LocalisationCache after cache is regenerated. + * + * @param WANObjectCache $cache + */ + public static function clearGlobalCacheEntry( WANObjectCache $cache ) { // Disable hold-off because: // - LocalisationCache is populated by messages on-disk and don't have DB lag, // thus there is no need for hold off. We only clear it after new localisation -- 2.20.1