From d421f22eb6e7d09d088fb03355796c1e776eb2dc Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 12 Aug 2019 17:46:14 -0700 Subject: [PATCH] objectcache: make newFromId()/newWANcacheFromId()/getDefaultKeyspace() private Change-Id: I30b99f23dbd9637ca8178d3a3650b4c38ec43e7d --- includes/ServiceWiring.php | 3 ++- includes/objectcache/ObjectCache.php | 6 +++--- includes/registration/ExtensionRegistry.php | 7 +++---- tests/phpunit/includes/libs/objectcache/BagOStuffTest.php | 7 ++++--- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index c192b5a266..0041f4257a 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -267,9 +267,10 @@ return [ }, 'LocalServerObjectCache' => function ( MediaWikiServices $services ) : BagOStuff { + $config = $services->getMainConfig(); $cacheId = \ObjectCache::detectLocalServerCache(); - return \ObjectCache::newFromId( $cacheId ); + return \ObjectCache::newFromParams( $config->get( 'ObjectCaches' )[$cacheId] ); }, 'MagicWordFactory' => function ( MediaWikiServices $services ) : MagicWordFactory { diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index 3bb077173f..ad0f67e590 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -119,7 +119,7 @@ class ObjectCache { * @return BagOStuff * @throws InvalidArgumentException */ - public static function newFromId( $id ) { + private static function newFromId( $id ) { global $wgObjectCaches; if ( !isset( $wgObjectCaches[$id] ) ) { @@ -146,7 +146,7 @@ class ObjectCache { * * @return string */ - public static function getDefaultKeyspace() { + private static function getDefaultKeyspace() { global $wgCachePrefix; $keyspace = $wgCachePrefix; @@ -297,7 +297,7 @@ class ObjectCache { * @return WANObjectCache * @throws UnexpectedValueException */ - public static function newWANCacheFromId( $id ) { + private static function newWANCacheFromId( $id ) { global $wgWANObjectCaches, $wgObjectCaches; if ( !isset( $wgWANObjectCaches[$id] ) ) { diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php index 9cae73c907..3e65f6c1ba 100644 --- a/includes/registration/ExtensionRegistry.php +++ b/includes/registration/ExtensionRegistry.php @@ -146,7 +146,7 @@ class ExtensionRegistry { * be loaded then). */ public function loadFromQueue() { - global $wgVersion, $wgDevelopmentWarnings; + global $wgVersion, $wgDevelopmentWarnings, $wgObjectCaches; if ( !$this->queued ) { return; } @@ -169,10 +169,9 @@ class ExtensionRegistry { // We use a try/catch because we don't want to fail here // if $wgObjectCaches is not configured properly for APC setup try { - // Don't use MediaWikiServices here to prevent instantiating it before extensions have - // been loaded + // Avoid MediaWikiServices to prevent instantiating it before extensions have loaded $cacheId = ObjectCache::detectLocalServerCache(); - $cache = ObjectCache::newFromId( $cacheId ); + $cache = ObjectCache::newFromParams( $wgObjectCaches[$cacheId] ); } catch ( InvalidArgumentException $e ) { $cache = new EmptyBagOStuff(); } diff --git a/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php b/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php index 9ec86bce79..f9176e5dd3 100644 --- a/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php +++ b/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php @@ -19,9 +19,10 @@ class BagOStuffTest extends MediaWikiTestCase { // type defined through parameter if ( $this->getCliArg( 'use-bagostuff' ) !== null ) { - $name = $this->getCliArg( 'use-bagostuff' ); + global $wgObjectCaches; - $this->cache = ObjectCache::newFromId( $name ); + $id = $this->getCliArg( 'use-bagostuff' ); + $this->cache = ObjectCache::newFromParams( $wgObjectCaches[$id] ); } else { // no type defined - use simple hash $this->cache = new HashBagOStuff; @@ -36,7 +37,7 @@ class BagOStuffTest extends MediaWikiTestCase { * @covers MediumSpecificBagOStuff::makeKeyInternal */ public function testMakeKey() { - $cache = ObjectCache::newFromId( 'hash' ); + $cache = new HashBagOStuff(); $localKey = $cache->makeKey( 'first', 'second', 'third' ); $globalKey = $cache->makeGlobalKey( 'first', 'second', 'third' ); -- 2.20.1