mediawiki-extensions-Echo/includes/Cache/TitleLocalCache.php
Daimona Eaytoy ef50bfeda5 Make Title and Revision caches proper services
Singletons are bad, amongst other reasons, because they're never reset
in tests. They can therefore occasionally cause test failures if the
cached data stored in one of these singletons becomes stale.

As noted on the task, ideally these two classes shouldn't exist at all,
and core should be responsible for caching the information it deems
expensive to compute.

As a temporary (TM) workaround, make both classes actual services, so
that the setUp/tearDown logic in MediaWikiIntegrationTestCase can
properly reset them between tests.

Dependencies are intentionally not being injected, precisely because
these classes should just be deleted, not improved.

Bug: T344124
Change-Id: I58b8d9610f9447468235b94d25732528ab6acce6
2023-08-14 17:41:23 +02:00

35 lines
878 B
PHP

<?php
namespace MediaWiki\Extension\Notifications\Cache;
use MediaWiki\MediaWikiServices;
use MediaWiki\Page\PageRecord;
/**
* Cache class that maps article id to Title object.
* @fixme There should be no need for this class. Core's PageStore should be responsible for caching, if it's
* deemed necessary. See also T344124.
*/
class TitleLocalCache extends LocalCache {
/**
* @inheritDoc
*/
protected function resolve( array $lookups ) {
if ( $lookups ) {
$titles = MediaWikiServices::getInstance()
->getPageStore()
->newSelectQueryBuilder()
->wherePageIds( $lookups )
->caller( __METHOD__ )
->fetchPageRecords();
/** @var PageRecord $title */
foreach ( $titles as $title ) {
$title = MediaWikiServices::getInstance()->getTitleFactory()->castFromPageIdentity( $title );
yield $title->getArticleID() => $title;
}
}
}
}