Skip to content

Commit

Permalink
Merge "Prefetch terms on non-entity histories"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Dec 13, 2024
2 parents 55a0424 + 09b0262 commit a9ed96a
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 66 deletions.
1 change: 0 additions & 1 deletion extension-repo.json
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,6 @@
"factory": "\\Wikibase\\Repo\\Hooks\\PageHistoryPagerHookHandler::factory",
"services": [
"WikibaseRepo.LanguageFallbackChainFactory",
"WikibaseRepo.LinkTargetEntityIdLookup",
"WikibaseRepo.PrefetchingTermLookup"
]
},
Expand Down
13 changes: 0 additions & 13 deletions repo/includes/Hooks/PageHistoryPagerHookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Wikibase\DataAccess\PrefetchingTermLookup;
use Wikibase\DataModel\Term\TermTypes;
use Wikibase\Lib\LanguageFallbackChainFactory;
use Wikibase\Lib\Store\LinkTargetEntityIdLookup;
use Wikimedia\Rdbms\IResultWrapper;

//phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
Expand All @@ -21,30 +20,24 @@
*/
class PageHistoryPagerHookHandler implements PageHistoryPager__doBatchLookupsHook {

private LinkTargetEntityIdLookup $linkTargetEntityIdLookup;

private LanguageFallbackChainFactory $languageFallbackChainFactory;

private SummaryParsingPrefetchHelper $summaryParsingPrefetchHelper;

public function __construct(
PrefetchingTermLookup $prefetchingLookup,
LinkTargetEntityIdLookup $linkTargetEntityIdLookup,
LanguageFallbackChainFactory $languageFallbackChainFactory
) {
$this->linkTargetEntityIdLookup = $linkTargetEntityIdLookup;
$this->languageFallbackChainFactory = $languageFallbackChainFactory;
$this->summaryParsingPrefetchHelper = new SummaryParsingPrefetchHelper( $prefetchingLookup );
}

public static function factory(
LanguageFallbackChainFactory $languageFallbackChainFactory,
LinkTargetEntityIdLookup $linkTargetEntityIdLookup,
PrefetchingTermLookup $prefetchingTermLookup
): self {
return new self(
$prefetchingTermLookup,
$linkTargetEntityIdLookup,
$languageFallbackChainFactory,
);
}
Expand All @@ -54,12 +47,6 @@ public static function factory(
* @param IResultWrapper $result
*/
public function onPageHistoryPager__doBatchLookups( $pager, $result ) {
$entityId = $this->linkTargetEntityIdLookup->getEntityId( $pager->getTitle() );
if ( $entityId === null ) {
// XXX: This means we only prefetch when showing the edit history of an entity.
return;
}

$languageFallbackChain = $this->languageFallbackChainFactory->newFromContext( $pager->getContext() );

$this->summaryParsingPrefetchHelper->prefetchTermsForMentionedEntities(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use MediaWiki\Context\IContextSource;
use MediaWiki\Pager\HistoryPager;
use MediaWiki\Title\Title;
use PHPUnit\Framework\TestCase;
use Wikibase\DataAccess\PrefetchingTermLookup;
use Wikibase\DataModel\Entity\Item;
Expand All @@ -19,7 +18,6 @@
use Wikibase\Lib\ContentLanguages;
use Wikibase\Lib\LanguageFallbackChainFactory;
use Wikibase\Lib\LanguageWithConversion;
use Wikibase\Lib\Store\LinkTargetEntityIdLookup;
use Wikibase\Lib\TermLanguageFallbackChain;
use Wikibase\Repo\Hooks\PageHistoryPagerHookHandler;
use Wikimedia\Rdbms\IResultWrapper;
Expand All @@ -37,9 +35,6 @@ class PageHistoryPagerHookHandlerTest extends TestCase {
/** @var PrefetchingTermLookup */
private $prefetchingLookup;

/** @var LinkTargetEntityIdLookup */
private $linkTargetEntityIdLookup;

/** @var LanguageFallbackChainFactory */
private $languageFallbackChainFactory;

Expand All @@ -52,29 +47,20 @@ class PageHistoryPagerHookHandlerTest extends TestCase {
/** @var HistoryPager|null */
private $pager;

/** @var ItemId */
private $entityId;

/** @var Item */
private $entity;

/** @var IResultWrapper|null */
private $resultWrapper;

/** @var Title */
private $title;

protected function setUp(): void {
$this->entityId = new ItemId( 'Q1' );
$this->entity = new Item( $this->entityId );
$this->title = Title::newFromTextThrow( $this->entityId->getSerialization() );
$this->entity = new Item( new ItemId( 'Q1' ) );

$this->pager = $this->createMock( HistoryPager::class );
$this->resultWrapper = $this->createMock( IResultWrapper::class );

$this->prefetchingLookup = $this->createMock( PrefetchingTermLookup::class );
$this->languageFallbackChainFactory = $this->createMock( LanguageFallbackChainFactory::class );
$this->linkTargetEntityIdLookup = $this->createMock( LinkTargetEntityIdLookup::class );

$stubContentLanguages = $this->createStub( ContentLanguages::class );
$stubContentLanguages->method( 'hasLanguage' )
Expand All @@ -99,7 +85,6 @@ protected function setUp(): void {
private function getHookHandler() {
return new PageHistoryPagerHookHandler(
$this->prefetchingLookup,
$this->linkTargetEntityIdLookup,
$this->languageFallbackChainFactory
);
}
Expand Down Expand Up @@ -138,15 +123,6 @@ public function testDoBatchLookups() {

$this->setupResultWithSummaries( $this->entity->getStatements() );

$this->pager->expects( $this->once() )
->method( 'getTitle' )
->willReturn( $this->title );

$this->linkTargetEntityIdLookup->expects( $this->once() )
->method( 'getEntityId' )
->with( $this->title )
->willReturn( $this->entityId );

$this->prefetchingLookup->expects( $this->once() )
->method( 'prefetchTerms' )
->with(
Expand All @@ -170,33 +146,6 @@ public function testDoBatchLookups() {
public function testDontPrefetchEmptySummary() {
$this->setupResultWithSummaries( new StatementList() );

$this->pager->expects( $this->once() )
->method( 'getTitle' )
->willReturn( $this->title );

$this->linkTargetEntityIdLookup->expects( $this->once() )
->method( 'getEntityId' )
->with( $this->title )
->willReturn( $this->entityId );

$this->prefetchingLookup->expects( $this->never() )
->method( 'prefetchTerms' );

$handler = $this->getHookHandler();

$handler->onPageHistoryPager__doBatchLookups( $this->pager, $this->resultWrapper );
}

public function testShouldSkipIfNotEntityId() {
$this->pager->expects( $this->once() )
->method( 'getTitle' )
->willReturn( $this->title );

$this->linkTargetEntityIdLookup->expects( $this->once() )
->method( 'getEntityId' )
->with( $this->title )
->willReturn( null );

$this->prefetchingLookup->expects( $this->never() )
->method( 'prefetchTerms' );

Expand Down

0 comments on commit a9ed96a

Please sign in to comment.