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

Change subject: Split page set before constructing InjectRCRecordsJob
......................................................................

Split page set before constructing InjectRCRecordsJob

Bug: T175316
Change-Id: If11f0cec4659dd65e3e5b05a64311037b14d7fab
---
M client/includes/Changes/InjectRCRecordsJob.php
M client/includes/Changes/WikiPageUpdater.php
M client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
M client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
4 files changed, 21 insertions(+), 78 deletions(-)


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

diff --git a/client/includes/Changes/InjectRCRecordsJob.php 
b/client/includes/Changes/InjectRCRecordsJob.php
index d47acb6..72927a8 100644
--- a/client/includes/Changes/InjectRCRecordsJob.php
+++ b/client/includes/Changes/InjectRCRecordsJob.php
@@ -68,11 +68,6 @@
        private $stats = null;
 
        /**
-        * @var int Batch size for database operations
-        */
-       private $dbBatchSize = 100;
-
-       /**
         * @param Title[] $titles
         * @param EntityChange $change
         *
@@ -184,14 +179,6 @@
        }
 
        /**
-        * @param int $dbBatchSize
-        */
-       public function setDbBatchSize( $dbBatchSize ) {
-               Assert::parameterType( 'integer', $dbBatchSize, '$dbBatchSize' 
);
-               $this->dbBatchSize = $dbBatchSize;
-       }
-
-       /**
         * Returns the change that should be processed.
         *
         * EntityChange objects are loaded using a EntityChangeLookup.
@@ -261,7 +248,6 @@
 
                $rcAttribs = $this->rcFactory->prepareChangeAttributes( $change 
);
 
-               $c = 0;
                $trxToken = $this->lbFactory->getEmptyTransactionTicket( 
__METHOD__ );
 
                foreach ( $titles as $title ) {
@@ -279,17 +265,9 @@
                                $this->logger->debug( __FUNCTION__ . ": saving 
RC entry for " . $title->getFullText() );
                                $rc->save();
                        }
-
-                       if ( ++$c >= $this->dbBatchSize ) {
-                               $this->lbFactory->commitAndWaitForReplication( 
__METHOD__, $trxToken );
-                               $trxToken = 
$this->lbFactory->getEmptyTransactionTicket( __METHOD__ );
-                               $c = 0;
-                       }
                }
 
-               if ( $c > 0 ) {
-                       $this->lbFactory->commitAndWaitForReplication( 
__METHOD__, $trxToken );
-               }
+               $this->lbFactory->commitAndWaitForReplication( __METHOD__, 
$trxToken );
 
                $this->incrementStats( 'InjectRCRecords.run.titles', count( 
$titles ) );
 
diff --git a/client/includes/Changes/WikiPageUpdater.php 
b/client/includes/Changes/WikiPageUpdater.php
index 027e957..f7da3fe 100644
--- a/client/includes/Changes/WikiPageUpdater.php
+++ b/client/includes/Changes/WikiPageUpdater.php
@@ -113,7 +113,7 @@
                /* @var Title[] $batch */
                foreach ( $titleBatches as $batch ) {
                        wfDebugLog( __CLASS__, __FUNCTION__ . ": scheduling 
HTMLCacheUpdateJob for "
-                                            . count( $batch ) . " titles" );
+                               . count( $batch ) . " titles" );
 
                        $dummyTitle = Title::makeTitle( NS_SPECIAL, 'Badtitle/' 
. __CLASS__ );
 
@@ -195,11 +195,19 @@
                        return;
                }
 
-               $jobSpec = InjectRCRecordsJob::makeJobSpecification( $titles, 
$change );
+               $jobs = [];
+               $titleBatches = array_chunk( $titles, $this->dbBatchSize );
 
-               $this->jobQueueGroup->lazyPush( $jobSpec );
+               /* @var Title[] $batch */
+               foreach ( $titleBatches as $batch ) {
+                       wfDebugLog( __CLASS__, __FUNCTION__ . ": scheduling 
InjectRCRecords for "
+                               . count( $batch ) . " titles" );
 
-               $this->incrementStats( 'InjectRCRecords.jobs', 1 );
+                       $jobs[] = InjectRCRecordsJob::makeJobSpecification( 
$batch, $change );
+               }
+
+               $this->jobQueueGroup->lazyPush( $jobs );
+               $this->incrementStats( 'InjectRCRecords.jobs', count( $jobs ) );
                $this->incrementStats( 'InjectRCRecords.titles', count( $titles 
) );
        }
 
diff --git a/client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php 
b/client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
index 41c54bf..578b5f3 100644
--- a/client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
+++ b/client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
@@ -9,7 +9,6 @@
 use Wikibase\Client\RecentChanges\RecentChangeFactory;
 use Wikibase\Client\RecentChanges\RecentChangesDuplicateDetector;
 use Wikibase\Client\Store\TitleFactory;
-use Wikibase\Client\WikibaseClient;
 use Wikibase\DataModel\Entity\BasicEntityIdParser;
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\DataModel\Entity\ItemId;
@@ -19,7 +18,6 @@
 use Wikibase\ItemChange;
 use Wikibase\Lib\Changes\EntityChangeFactory;
 use Wikibase\Lib\Store\Sql\EntityChangeLookup;
-use Wikibase\Lib\Tests\Changes\EntityChangeFactoryTest;
 use Wikimedia\Rdbms\LBFactory;
 use Wikimedia\TestingAccessWrapper;
 
@@ -449,45 +447,6 @@
 
                $job->setTitleFactory( $this->getTitleFactoryMock() );
                $job->setRecentChangesDuplicateDetector( $rcDupeDetector );
-
-               $job->run();
-       }
-
-       public function testRun_batch() {
-               $change = $this->getEntityChangeMock();
-               $rc = $this->getRecentChangeMock();
-               $changeLookup = $this->getEntityChangeLookupMock( [ $change ] );
-               $changeFactory = $this->getEntityChangeFactory();
-
-               $rcFactory = $this->getRCFactoryMock();
-
-               $rcFactory->expects( $this->any() )
-                       ->method( 'newRecentChange' )
-                       ->will( $this->returnValue( $rc ) );
-
-               $lbFactory = $this->getLBFactoryMock();
-               $lbFactory->expects( $this->exactly( 2 ) )
-                       ->method( 'commitAndWaitForReplication' );
-
-               $params = [
-                       'change' => $change->getId(),
-                       'pages' => [
-                               21 => [ 0, 'Foo' ],
-                               22 => [ 0, 'Bar' ],
-                               23 => [ 0, 'Cuzz' ],
-                       ]
-               ];
-
-               $job = new InjectRCRecordsJob(
-                       $lbFactory,
-                       $changeLookup,
-                       $changeFactory,
-                       $rcFactory,
-                       $params
-               );
-
-               $job->setTitleFactory( $this->getTitleFactoryMock() );
-               $job->setDbBatchSize( 2 );
 
                $job->run();
        }
diff --git a/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php 
b/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
index 37e33d5..1c8e57c 100644
--- a/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
+++ b/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
@@ -2,7 +2,6 @@
 
 namespace Wikibase\Client\Tests\Changes;
 
-use IJobSpecification;
 use HTMLCacheUpdateJob;
 use Job;
 use JobQueueGroup;
@@ -231,15 +230,14 @@
                $pages = [];
                $jobQueueGroup->expects( $this->atLeastOnce() )
                        ->method( 'lazyPush' )
-                       ->will( $this->returnCallback( function( 
IJobSpecification $job ) use ( &$pages, $change ) {
-                               $params = $job->getParams();
-
-                               $this->assertArrayHasKey( 'change', $params, 
'$params["change"]' );
-                               $this->assertArrayHasKey( 'pages', $params, 
'$params["pages"]' );
-
-                               $this->assertSame( $change->getId(), 
$params['change']['id'] );
-
-                               $pages += $params['pages']; // addition uses 
keys, array_merge does not
+                       ->will( $this->returnCallback( function( array $jobs ) 
use ( &$pages ) {
+                               /** @var Job $job */
+                               foreach ( $jobs as $job ) {
+                                       $this->assertSame( 
'wikibase-InjectRCRecords', $job->getType() );
+                                       $params = $job->getParams();
+                                       $this->assertArrayHasKey( 'pages', 
$params, '$params["pages"]' );
+                                       $pages += $params['pages']; // addition 
uses keys, array_merge does not
+                               }
                        } ) );
 
                $updater = new WikiPageUpdater(

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If11f0cec4659dd65e3e5b05a64311037b14d7fab
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: wmf/1.30.0-wmf.18
Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to