Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/364198 )

Change subject: Use multi-page RefreshLinksJobs in WikiPageUpdater
......................................................................

Use multi-page RefreshLinksJobs in WikiPageUpdater

Bug: T164173
Change-Id: If704b86a42487c7849487ecb00073c7e44091ecb
---
M client/includes/Changes/WikiPageUpdater.php
M client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
2 files changed, 83 insertions(+), 42 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/98/364198/1

diff --git a/client/includes/Changes/WikiPageUpdater.php 
b/client/includes/Changes/WikiPageUpdater.php
index ff0ccce..7293723 100644
--- a/client/includes/Changes/WikiPageUpdater.php
+++ b/client/includes/Changes/WikiPageUpdater.php
@@ -130,22 +130,49 @@
         * @param Title[] $titles The Titles of the pages to update
         */
        public function scheduleRefreshLinks( array $titles ) {
-               /* @var Title $title */
-               foreach ( $titles as $title ) {
-                       wfDebugLog( __CLASS__, __FUNCTION__ . ": scheduling 
refresh links for "
-                               . $title->getText() );
-
-                       $job = new RefreshLinksJob(
-                               $title,
-                               Job::newRootJobParams(
-                                       $title->getPrefixedDBkey()
-                               )
-                       );
-
-                       $this->jobQueueGroup->push( $job );
-                       $this->jobQueueGroup->deduplicateRootJob( $job );
+               if ( empty( $titles ) ) {
+                       return;
                }
-               $this->incrementStats( 'RefreshLinksJob', count( $titles ) );
+
+               $jobs = [];
+               $titleBatches = array_chunk( $titles, $this->dbBatchSize );
+
+               /* @var Title[] $batch */
+               foreach ( $titleBatches as $batch ) {
+                       wfDebugLog( __CLASS__, __FUNCTION__ . ": scheduling 
refresh links for "
+                               . count( $batch ) . " titles" );
+
+                       // NOTE: nominal title, will be ignored because the 
'pages' parameter is set.
+                       $title = reset( $batch );
+
+                       $jobs[] = new RefreshLinksJob(
+                               $title,
+                               [ 'pages' => 
$this->getPageParamForRefreshLinksJob( $batch ) ]
+                       );
+               }
+
+               $this->jobQueueGroup->lazyPush( $jobs );
+               $this->incrementStats( 'RefreshLinks-jobs', count( $jobs ) );
+               $this->incrementStats( 'RefreshLinks-titles', count( $titles ) 
);
+       }
+
+       /**
+        * @param Title[] $titles
+        *
+        * @returns array[] A Map of pageId => [ namespace, dbKey ]
+        */
+       private function getPageParamForRefreshLinksJob( array $titles ) {
+               $pages = [];
+
+               foreach ( $titles as $t ) {
+                       $id = $t->getArticleID();
+                       $pages[$id] = [
+                               $t->getNamespace(),
+                               $t->getDBkey()
+                       ];
+               }
+
+               return $pages;
        }
 
        /**
diff --git a/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php 
b/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
index f73f61f..407cd98 100644
--- a/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
+++ b/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
@@ -69,14 +69,14 @@
         *
         * @return Title
         */
-       private function getTitleMock( $text ) {
+       private function getTitleMock( $text, $id = 23 ) {
                $title = $this->getMockBuilder( Title::class )
                        ->disableOriginalConstructor()
                        ->getMock();
 
                $title->expects( $this->any() )
                        ->method( 'getArticleID' )
-                       ->will( $this->returnValue( 23 ) );
+                       ->will( $this->returnValue( $id ) );
 
                $title->expects( $this->any() )
                        ->method( 'exists' )
@@ -85,6 +85,22 @@
                $title->expects( $this->any() )
                        ->method( 'getPrefixedDBkey' )
                        ->will( $this->returnValue( $text ) );
+
+               $title->expects( $this->any() )
+                       ->method( 'getDBkey' )
+                       ->will( $this->returnValue( $text ) );
+
+               $title->expects( $this->any() )
+                       ->method( 'getText' )
+                       ->will( $this->returnValue( $text ) );
+
+               $title->expects( $this->any() )
+                       ->method( 'getNamespace' )
+                       ->will( $this->returnValue( 0 ) );
+
+               $title->expects( $this->any() )
+                       ->method( 'getNsText' )
+                       ->will( $this->returnValue( '' ) );
 
                return $title;
        }
@@ -136,7 +152,7 @@
                        ->method( 'invalidateCache' );
 
                $updater->purgeParserCache( [
-                       $title
+                       $title,
                ] );
        }
 
@@ -153,35 +169,28 @@
                        ->method( 'purgeSquid' );
 
                $updater->purgeWebCache( [
-                       $title
+                       $title,
                ] );
        }
 
        public function testScheduleRefreshLinks() {
-               $title = $this->getTitleMock( 'Foo' );
+               $titleFoo = $this->getTitleMock( 'Foo', 21 );
+               $titleBar = $this->getTitleMock( 'Bar', 22 );
+               $titleCuzz = $this->getTitleMock( 'Cuzz', 23 );
 
                $jobQueueGroup = $this->getJobQueueGroupMock();
 
-               $jobMatcher = function( RefreshLinksJob $job ) {
-                       $this->assertSame( 'Foo', 
$job->getTitle()->getPrefixedDBkey() );
-
-                       $expectedSignature = Job::newRootJobParams( 'Foo' );
-                       $actualSignature = $job->getRootJobParams();
-                       $this->assertSame(
-                               $expectedSignature['rootJobSignature'],
-                               $actualSignature['rootJobSignature']
-                       );
-
-                       return true;
-               };
-
-               $jobQueueGroup->expects( $this->any() )
-                       ->method( 'push' )
-                       ->with( $this->callback( $jobMatcher ) );
-
-               $jobQueueGroup->expects( $this->any() )
-                       ->method( 'deduplicateRootJob' )
-                       ->with( $this->callback( $jobMatcher ) );
+               $pages = [];
+               $jobQueueGroup->expects( $this->atLeastOnce() )
+                       ->method( 'lazyPush' )
+                       ->will( $this->returnCallback( function( array $jobs ) 
use ( &$pages ) {
+                               /** @var Job $job */
+                               foreach ( $jobs as $job ) {
+                                       $params = $job->getParams();
+                                       $this->assertArrayHasKey( 'pages', 
$params, '$params["pages"]' );
+                                       $pages += $params['pages']; // addition 
uses keys, array_merge does not
+                               }
+                       } ) );
 
                $updater = new WikiPageUpdater(
                        $jobQueueGroup,
@@ -191,8 +200,13 @@
                );
 
                $updater->scheduleRefreshLinks( [
-                       $title
+                       $titleFoo, $titleBar, $titleCuzz,
                ] );
+
+               $this->assertEquals( [ 21, 22, 23 ], array_keys( $pages ) );
+               $this->assertEquals( [ 0, 'Foo' ], $pages[21], '$pages[21]' );
+               $this->assertEquals( [ 0, 'Bar' ], $pages[22], '$pages[22]' );
+               $this->assertEquals( [ 0, 'Cuzz' ], $pages[23], '$pages[23]' );
        }
 
        public function testInjectRCRecords() {
@@ -221,7 +235,7 @@
                );
 
                $updater->injectRCRecords( [
-                       $title
+                       $title,
                ], $change );
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/364198
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If704b86a42487c7849487ecb00073c7e44091ecb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to