Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/286436
Change subject: Add LinkCache to MediaWikiServices
......................................................................
Add LinkCache to MediaWikiServices
Change-Id: I55c668a599976d0be6f326f0f446c479c2f2c206
---
M includes/MediaWikiServices.php
M includes/ServiceWiring.php
M includes/cache/LinkCache.php
M tests/phpunit/includes/MediaWikiServicesTest.php
M tests/phpunit/includes/content/ContentHandlerTest.php
5 files changed, 25 insertions(+), 47 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/36/286436/1
diff --git a/includes/MediaWikiServices.php b/includes/MediaWikiServices.php
index 33e59d2..7f0690e 100644
--- a/includes/MediaWikiServices.php
+++ b/includes/MediaWikiServices.php
@@ -7,6 +7,7 @@
use GlobalVarConfig;
use Hooks;
use LBFactory;
+use LinkCache;
use Liuggio\StatsdClient\Factory\StatsdDataFactory;
use LoadBalancer;
use MediaWiki\Services\ServiceContainer;
@@ -421,6 +422,13 @@
return $this->getService( 'WatchedItemStore' );
}
+ /**
+ * @return LinkCache
+ */
+ public function getLinkCache() {
+ return $this->getService( 'LinkCache' );
+ }
+
///////////////////////////////////////////////////////////////////////////
// NOTE: When adding a service getter here, don't forget to add a test
// case for it in MediaWikiServicesTest::provideGetters() and in
diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php
index fe45b23..ea62a6e 100644
--- a/includes/ServiceWiring.php
+++ b/includes/ServiceWiring.php
@@ -143,6 +143,15 @@
return $store;
},
+ 'LinkCache' => function( MediaWikiServices $services ) {
+ // How many Titles to store per cache.
+ $maxSize = 10000;
+ return new LinkCache(
+ new HashBagOStuff( [ 'maxKeys' => $maxSize ] ),
+ new HashBagOStuff( [ 'maxKeys' => $maxSize ] )
+ );
+ },
+
///////////////////////////////////////////////////////////////////////////
// NOTE: When adding a service here, don't forget to add a getter
function
// in the MediaWikiServices class. The convenience getter should just
call
diff --git a/includes/cache/LinkCache.php b/includes/cache/LinkCache.php
index b8f2329..34068f5 100644
--- a/includes/cache/LinkCache.php
+++ b/includes/cache/LinkCache.php
@@ -20,6 +20,7 @@
* @file
* @ingroup Cache
*/
+use MediaWiki\MediaWikiServices;
/**
* Cache for article titles (prefixed DB keys) and ids linked from one source
@@ -37,57 +38,20 @@
private $mBadLinks;
private $mForUpdate = false;
- /**
- * How many Titles to store. There are two caches, so the amount
actually
- * stored in memory can be up to twice this.
- */
- const MAX_SIZE = 10000;
-
- /**
- * @var LinkCache
- */
- protected static $instance;
-
- public function __construct() {
- $this->mGoodLinks = new HashBagOStuff( [ 'maxKeys' =>
self::MAX_SIZE ] );
- $this->mBadLinks = new HashBagOStuff( [ 'maxKeys' =>
self::MAX_SIZE ] );
+ public function __construct( BagOStuff $goodLinkCache, BagOStuff
$badLinkCache ) {
+ $this->mGoodLinks = $goodLinkCache;
+ $this->mBadLinks = $badLinkCache;
}
/**
* Get an instance of this class.
*
+ * @deprecated since 1.27 get a LinkCache from MediawikiServices
+ *
* @return LinkCache
*/
public static function singleton() {
- if ( !self::$instance ) {
- self::$instance = new LinkCache;
- }
-
- return self::$instance;
- }
-
- /**
- * Destroy the singleton instance
- *
- * A new one will be created next time singleton() is called.
- *
- * @since 1.22
- */
- public static function destroySingleton() {
- self::$instance = null;
- }
-
- /**
- * Set the singleton instance to a given object.
- *
- * Since we do not have an interface for LinkCache, you have to be sure
the
- * given object implements all the LinkCache public methods.
- *
- * @param LinkCache $instance
- * @since 1.22
- */
- public static function setSingleton( LinkCache $instance ) {
- self::$instance = $instance;
+ return MediaWikiServices::getInstance()->getLinkCache();
}
/**
diff --git a/tests/phpunit/includes/MediaWikiServicesTest.php
b/tests/phpunit/includes/MediaWikiServicesTest.php
index 6837a75..c8bfdb3 100644
--- a/tests/phpunit/includes/MediaWikiServicesTest.php
+++ b/tests/phpunit/includes/MediaWikiServicesTest.php
@@ -242,6 +242,7 @@
'DBLoadBalancerFactory' => [ 'DBLoadBalancerFactory',
'LBFactory' ],
'DBLoadBalancer' => [ 'DBLoadBalancer', 'LoadBalancer'
],
'WatchedItemStore' => [ 'WatchedItemStore',
WatchedItemStore::class ],
+ 'LinkCache' => [ 'LinkCache', LinkCache::class ],
];
}
diff --git a/tests/phpunit/includes/content/ContentHandlerTest.php
b/tests/phpunit/includes/content/ContentHandlerTest.php
index 91f27fb..9f590fe 100644
--- a/tests/phpunit/includes/content/ContentHandlerTest.php
+++ b/tests/phpunit/includes/content/ContentHandlerTest.php
@@ -35,8 +35,6 @@
// Reset namespace cache
MWNamespace::getCanonicalNamespaces( true );
$wgContLang->resetNamespaces();
- // And LinkCache
- LinkCache::destroySingleton();
}
protected function tearDown() {
@@ -45,8 +43,6 @@
// Reset namespace cache
MWNamespace::getCanonicalNamespaces( true );
$wgContLang->resetNamespaces();
- // And LinkCache
- LinkCache::destroySingleton();
parent::tearDown();
}
--
To view, visit https://gerrit.wikimedia.org/r/286436
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I55c668a599976d0be6f326f0f446c479c2f2c206
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits