diff --git a/client/includes/Changes/AffectedPagesFinder.php b/client/includes/Changes/AffectedPagesFinder.php index 39138ee6488..0d366085967 100644 --- a/client/includes/Changes/AffectedPagesFinder.php +++ b/client/includes/Changes/AffectedPagesFinder.php @@ -1,10 +1,14 @@ usageLookup = $usageLookup; $this->titleFactory = $titleFactory; + $this->linkBatchFactory = $linkBatchFactory; $this->siteId = $siteId; + $this->logger = $logger ?: new NullLogger(); $this->checkPageExistence = $checkPageExistence; - // TODO inject me - $this->logger = WikibaseClient::getDefaultInstance()->getLogger(); } /** @@ -335,6 +337,9 @@ private function makeVirtualUsages( array $titles, EntityId $entityId, array $as $usagesForItem[] = new EntityUsage( $entityId, $aspect, $modifier ); } + // bulk-load the page IDs into the LinkCache + $this->linkBatchFactory->newLinkBatch( $titles )->execute(); + $usagesPerPage = []; foreach ( $titles as $title ) { $pageId = $title->getArticleID(); diff --git a/client/includes/WikibaseClient.php b/client/includes/WikibaseClient.php index 0fbe076e5da..57a6af1c092 100644 --- a/client/includes/WikibaseClient.php +++ b/client/includes/WikibaseClient.php @@ -1123,7 +1123,9 @@ private function getAffectedPagesFinder(): AffectedPagesFinder { return new AffectedPagesFinder( $this->getStore()->getUsageLookup(), new TitleFactory(), - $this->settings->getSetting( 'siteGlobalID' ) + MediaWikiServices::getInstance()->getLinkBatchFactory(), + $this->settings->getSetting( 'siteGlobalID' ), + $this->getLogger() ); } diff --git a/client/tests/phpunit/integration/includes/Changes/AffectedPagesFinderTest.php b/client/tests/phpunit/integration/includes/Changes/AffectedPagesFinderTest.php index 103e8776727..c18a83d154e 100644 --- a/client/tests/phpunit/integration/includes/Changes/AffectedPagesFinderTest.php +++ b/client/tests/phpunit/integration/includes/Changes/AffectedPagesFinderTest.php @@ -1,10 +1,14 @@ createMock( LinkBatch::class ); + $linkBatch->method( 'execute' ) + ->willReturn( null ); + + $linkBatchFactory = $this->createMock( LinkBatchFactory::class ); + $linkBatchFactory->method( 'newLinkBatch' ) + ->willReturn( $linkBatch ); + + return $linkBatchFactory; + } + private function getAffectedPagesFinder( array $usage, array $expectedAspects ) { $usageLookup = $this->createMock( UsageLookup::class ); @@ -76,7 +92,9 @@ private function getAffectedPagesFinder( array $usage, array $expectedAspects ) $affectedPagesFinder = new AffectedPagesFinder( $usageLookup, $this->getTitleFactory(), + $this->getLinkBatchFactory(), 'enwiki', + null, false ); @@ -513,7 +531,9 @@ public function testGetAffectedUsagesByPage_withDeletedPage() { $affectedPagesFinder = new AffectedPagesFinder( $this->getSiteLinkUsageLookup( $pageTitle ), new TitleFactory(), + $this->getLinkBatchFactory(), 'enwiki', + null, false ); diff --git a/client/tests/phpunit/integration/includes/Changes/ChangeHandlerTest.php b/client/tests/phpunit/integration/includes/Changes/ChangeHandlerTest.php index d49e9c4c0f3..452a2939ac1 100644 --- a/client/tests/phpunit/integration/includes/Changes/ChangeHandlerTest.php +++ b/client/tests/phpunit/integration/includes/Changes/ChangeHandlerTest.php @@ -4,6 +4,7 @@ use ArrayIterator; use InvalidArgumentException; +use MediaWiki\MediaWikiServices; use MediaWikiIntegrationTestCase; use Psr\Log\NullLogger; use SiteLookup; @@ -44,7 +45,9 @@ private function getAffectedPagesFinder( UsageLookup $usageLookup, TitleFactory return new AffectedPagesFinder( $usageLookup, $titleFactory, + MediaWikiServices::getInstance()->getLinkBatchFactory(), 'enwiki', + null, false ); }