Merge "cache: Inject HookContainer into BacklinkCache"

This commit is contained in:
jenkins-bot 2022-12-14 22:03:37 +00:00 committed by Gerrit Code Review
commit 0fb254ffa5
4 changed files with 37 additions and 9 deletions

View file

@ -267,7 +267,10 @@ return [
},
'BacklinkCacheFactory' => static function ( MediaWikiServices $services ): BacklinkCacheFactory {
return new BacklinkCacheFactory( $services->getMainWANObjectCache() );
return new BacklinkCacheFactory(
$services->getMainWANObjectCache(),
$services->getHookContainer()
);
},
'BadFileLookup' => static function ( MediaWikiServices $services ): BadFileLookup {

View file

@ -26,7 +26,8 @@
*/
use MediaWiki\Cache\CacheKeyHelper;
use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\HookContainer\HookRunner;
use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices;
use MediaWiki\Page\PageIdentity;
@ -53,7 +54,6 @@ use Wikimedia\Rdbms\SelectQueryBuilder;
* Introduced by r47317
*/
class BacklinkCache {
use ProtectedHookAccessorTrait;
/** @var BacklinkCache */
protected static $instance;
@ -85,6 +85,9 @@ class BacklinkCache {
/** @var WANObjectCache */
protected $wanCache;
/** @var HookRunner */
private $hookRunner;
/**
* Local copy of a database object.
*
@ -106,11 +109,17 @@ class BacklinkCache {
* Create a new BacklinkCache
*
* @param WANObjectCache $wanCache
* @param HookContainer $hookContainer
* @param PageReference $page Page to create a backlink cache for
*/
public function __construct( WANObjectCache $wanCache, PageReference $page ) {
public function __construct(
WANObjectCache $wanCache,
HookContainer $hookContainer,
PageReference $page
) {
$this->page = $page;
$this->wanCache = $wanCache;
$this->hookRunner = new HookRunner( $hookContainer );
}
/**
@ -271,7 +280,7 @@ class BacklinkCache {
} else {
$prefix = null;
// @phan-suppress-next-line PhanTypeMismatchArgument Type mismatch on pass-by-ref args
$this->getHookRunner()->onBacklinkCacheGetPrefix( $table, $prefix );
$this->hookRunner->onBacklinkCacheGetPrefix( $table, $prefix );
if ( $prefix ) {
return $prefix;
} else {
@ -342,7 +351,7 @@ class BacklinkCache {
default:
$knownTable = false;
$conds = null;
$this->getHookRunner()->onBacklinkCacheGetConditions( $table,
$this->hookRunner->onBacklinkCacheGetConditions( $table,
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable castFrom does not return null here
Title::castFromPageReference( $this->page ),
// @phan-suppress-next-line PhanTypeMismatchArgument Type mismatch on pass-by-ref args

View file

@ -24,6 +24,7 @@
namespace MediaWiki\Cache;
use BacklinkCache;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\Page\PageReference;
use WANObjectCache;
@ -37,11 +38,19 @@ class BacklinkCacheFactory {
/** @var WANObjectCache */
private $wanCache;
/** @var HookContainer */
private $hookContainer;
/**
* @param WANObjectCache $wanCache
* @param HookContainer $hookContainer
*/
public function __construct( WANObjectCache $wanCache ) {
public function __construct(
WANObjectCache $wanCache,
HookContainer $hookContainer
) {
$this->wanCache = $wanCache;
$this->hookContainer = $hookContainer;
}
/**
@ -56,7 +65,11 @@ class BacklinkCacheFactory {
*/
public function getBacklinkCache( PageReference $page ): BacklinkCache {
if ( !$this->latestBacklinkCache || !$this->latestBacklinkCache->getPage()->isSamePageAs( $page ) ) {
$this->latestBacklinkCache = new BacklinkCache( $this->wanCache, $page );
$this->latestBacklinkCache = new BacklinkCache(
$this->wanCache,
$this->hookContainer,
$page
);
}
return $this->latestBacklinkCache;
}

View file

@ -14,7 +14,10 @@ class BacklinkCacheFactoryTest extends MediaWikiUnitTestCase {
public function testGetBacklinkCache() {
$wanCache = new WANObjectCache( [ 'cache' => new EmptyBagOStuff() ] );
$page = PageReferenceValue::localReference( NS_CATEGORY, "kittens" );
$factory = new BacklinkCacheFactory( $wanCache );
$factory = new BacklinkCacheFactory(
$wanCache,
$this->createHookContainer()
);
$cache = $factory->getBacklinkCache( $page );
$this->assertTrue( $cache->getPage()->isSamePageAs( $page ) );