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

Change subject: Pass root job params through WikiPageUpdater
......................................................................

Pass root job params through WikiPageUpdater

Root job timestamps help with deduplication.

Change-Id: I566d2253080a0e8fb74526f33763d23f7ecdadcf
---
M client/includes/ChangeNotificationJob.php
M client/includes/Changes/ChangeHandler.php
M client/includes/Changes/InjectRCRecordsJob.php
M client/includes/Changes/PageUpdater.php
M client/includes/Changes/WikiPageUpdater.php
M client/tests/phpunit/includes/Changes/MockPageUpdater.php
M docs/hooks.txt
7 files changed, 61 insertions(+), 32 deletions(-)


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

diff --git a/client/includes/ChangeNotificationJob.php 
b/client/includes/ChangeNotificationJob.php
index 3822471..2a4fe72 100644
--- a/client/includes/ChangeNotificationJob.php
+++ b/client/includes/ChangeNotificationJob.php
@@ -96,7 +96,7 @@
                $changes = $this->getChanges();
 
                $changeHandler = $this->getChangeHandler();
-               $changeHandler->handleChanges( $changes );
+               $changeHandler->handleChanges( $changes, 
$this->getRootJobParams() );
 
                if ( $changes ) {
                        /* @var EntityChange $last */
diff --git a/client/includes/Changes/ChangeHandler.php 
b/client/includes/Changes/ChangeHandler.php
index 8d8046d..ad39923 100644
--- a/client/includes/Changes/ChangeHandler.php
+++ b/client/includes/Changes/ChangeHandler.php
@@ -75,20 +75,21 @@
 
        /**
         * @param EntityChange[] $changes
+        * @param array $rootJobParams any relevant root job parameters to be 
inherited by new jobs.
         */
-       public function handleChanges( array $changes ) {
+       public function handleChanges( array $changes, array $rootJobParams = 
[] ) {
                $changes = $this->changeRunCoalescer->transformChangeList( 
$changes );
 
-               if ( !Hooks::run( 'WikibaseHandleChanges', [ $changes ] ) ) {
+               if ( !Hooks::run( 'WikibaseHandleChanges', [ $changes, 
$rootJobParams ] ) ) {
                        return;
                }
 
                foreach ( $changes as $change ) {
-                       if ( !Hooks::run( 'WikibaseHandleChange', [ $change ] ) 
) {
+                       if ( !Hooks::run( 'WikibaseHandleChange', [ $change, 
$rootJobParams ] ) ) {
                                continue;
                        }
 
-                       $this->handleChange( $change );
+                       $this->handleChange( $change, $rootJobParams );
                }
        }
 
@@ -98,10 +99,9 @@
         * @todo: process multiple changes at once!
         *
         * @param EntityChange $change
-        *
-        * @throws MWException
+        * @param array $rootJobParams any relevant root job parameters to be 
inherited by new jobs.
         */
-       public function handleChange( EntityChange $change ) {
+       public function handleChange( EntityChange $change, array 
$rootJobParams = [] ) {
                $changeId = $this->getChangeIdForLog( $change );
                wfDebugLog( __CLASS__, __FUNCTION__ . ": handling change 
#$changeId"
                        . ' (' . $change->getType() . ')' );
@@ -116,9 +116,9 @@
 
                ( new LinkBatch( $titlesToUpdate ) )->execute();
 
-               $this->updater->purgeWebCache( $titlesToUpdate );
-               $this->updater->scheduleRefreshLinks( $titlesToUpdate );
-               $this->updater->injectRCRecords( $titlesToUpdate, $change );
+               $this->updater->purgeWebCache( $titlesToUpdate, $rootJobParams 
);
+               $this->updater->scheduleRefreshLinks( $titlesToUpdate, 
$rootJobParams );
+               $this->updater->injectRCRecords( $titlesToUpdate, $change, 
$rootJobParams );
                // TODO: inject dummy revisions
        }
 
diff --git a/client/includes/Changes/InjectRCRecordsJob.php 
b/client/includes/Changes/InjectRCRecordsJob.php
index d47acb6..2f0a712 100644
--- a/client/includes/Changes/InjectRCRecordsJob.php
+++ b/client/includes/Changes/InjectRCRecordsJob.php
@@ -75,10 +75,15 @@
        /**
         * @param Title[] $titles
         * @param EntityChange $change
+        * @param array $rootJobParams
         *
         * @return JobSpecification
         */
-       public static function makeJobSpecification( array $titles, 
EntityChange $change ) {
+       public static function makeJobSpecification(
+               array $titles,
+               EntityChange $change,
+               array $rootJobParams = []
+       ) {
                $pages = [];
 
                foreach ( $titles as $t ) {
@@ -91,10 +96,10 @@
                $changeData = $change->getFields();
                $changeData['info'] = $change->getSerializedInfo( [ 'changes' ] 
);
 
-               $params = [
+               $params = array_merge( $rootJobParams, [
                        'change' => $changeData,
                        'pages' => $pages
-               ];
+               ] );
 
                return new JobSpecification(
                        'wikibase-InjectRCRecords',
diff --git a/client/includes/Changes/PageUpdater.php 
b/client/includes/Changes/PageUpdater.php
index 391f122..b3b77ed 100644
--- a/client/includes/Changes/PageUpdater.php
+++ b/client/includes/Changes/PageUpdater.php
@@ -20,22 +20,25 @@
         * Invalidates external web cached of the given pages.
         *
         * @param Title[] $titles The Titles of the pages to update
+        * @param array $rootJobParams any relevant root job parameters to be 
inherited by new jobs.
         */
-       public function purgeWebCache( array $titles );
+       public function purgeWebCache( array $titles, array $rootJobParams = [] 
);
 
        /**
         * Schedules RefreshLinks jobs for the given titles
         *
         * @param Title[] $titles The Titles of the pages to update
+        * @param array $rootJobParams any relevant root job parameters to be 
inherited by new jobs.
         */
-       public function scheduleRefreshLinks( array $titles );
+       public function scheduleRefreshLinks( array $titles, array 
$rootJobParams = [] );
 
        /**
         * Injects an RC entry into the recentchanges, using the the given 
title and attribs
         *
         * @param Title[] $titles
         * @param EntityChange $change
+        * @param array $rootJobParams any relevant root job parameters to be 
inherited by new jobs.
         */
-       public function injectRCRecords( array $titles, EntityChange $change );
+       public function injectRCRecords( array $titles, EntityChange $change, 
array $rootJobParams = [] );
 
 }
diff --git a/client/includes/Changes/WikiPageUpdater.php 
b/client/includes/Changes/WikiPageUpdater.php
index 027e957..f42073b 100644
--- a/client/includes/Changes/WikiPageUpdater.php
+++ b/client/includes/Changes/WikiPageUpdater.php
@@ -98,11 +98,27 @@
        }
 
        /**
+        * @param array $params
+        * @param array $rootJobParams
+        * @return array
+        */
+       private function addRootJobParameters( array $params, array 
$rootJobParams ) {
+               if ( isset( $rootJobParams['rootJobTimestamp'] ) ) {
+                       $params['rootJobTimestamp'] = 
$rootJobParams['rootJobTimestamp'];
+               } else {
+                       $params['rootJobTimestamp'] = wfTimestampNow();
+               }
+
+               return $params;
+       }
+
+       /**
         * Invalidates external web cached of the given pages.
         *
         * @param Title[] $titles The Titles of the pages to update
+        * @param array $rootJobParams
         */
-       public function purgeWebCache( array $titles ) {
+       public function purgeWebCache( array $titles, array $rootJobParams = [] 
) {
                if ( $titles === [] ) {
                        return;
                }
@@ -119,10 +135,9 @@
 
                        $jobs[] = new HTMLCacheUpdateJob(
                                $dummyTitle, // the title will be ignored 
because the 'pages' parameter is set.
-                               [
-                                       'pages' => 
$this->getPageParamForRefreshLinksJob( $batch ),
-                                       'rootJobTimestamp' => wfTimestampNow()
-                               ]
+                               $this->addRootJobParameters( [
+                                       'pages' => 
$this->getPageParamForRefreshLinksJob( $batch )
+                               ], $rootJobParams )
                        );
                }
 
@@ -135,8 +150,9 @@
         * Schedules RefreshLinks jobs for the given titles
         *
         * @param Title[] $titles The Titles of the pages to update
+        * @param array $rootJobParams
         */
-       public function scheduleRefreshLinks( array $titles ) {
+       public function scheduleRefreshLinks( array $titles, array 
$rootJobParams = [] ) {
                if ( $titles === [] ) {
                        return;
                }
@@ -153,10 +169,9 @@
 
                        $jobs[] = new RefreshLinksJob(
                                $dummyTitle, // the title will be ignored 
because the 'pages' parameter is set.
-                               [
+                               $this->addRootJobParameters( [
                                        'pages' => 
$this->getPageParamForRefreshLinksJob( $batch ),
-                                       'rootJobTimestamp' => wfTimestampNow(),
-                               ]
+                               ], $rootJobParams )
                        );
                }
 
@@ -189,13 +204,14 @@
         *
         * @param Title[] $titles
         * @param EntityChange $change
+        * @param array $rootJobParams
         */
-       public function injectRCRecords( array $titles, EntityChange $change ) {
+       public function injectRCRecords( array $titles, EntityChange $change, 
array $rootJobParams = [] ) {
                if ( $titles === [] ) {
                        return;
                }
 
-               $jobSpec = InjectRCRecordsJob::makeJobSpecification( $titles, 
$change );
+               $jobSpec = InjectRCRecordsJob::makeJobSpecification( $titles, 
$change, $rootJobParams );
 
                $this->jobQueueGroup->lazyPush( $jobSpec );
 
diff --git a/client/tests/phpunit/includes/Changes/MockPageUpdater.php 
b/client/tests/phpunit/includes/Changes/MockPageUpdater.php
index 02a7028..a7d2bb1 100644
--- a/client/tests/phpunit/includes/Changes/MockPageUpdater.php
+++ b/client/tests/phpunit/includes/Changes/MockPageUpdater.php
@@ -25,8 +25,9 @@
 
        /**
         * @param Title[] $titles
+        * @param array $rootJobParams
         */
-       public function purgeWebCache( array $titles ) {
+       public function purgeWebCache( array $titles, array $rootJobParams = [] 
) {
                foreach ( $titles as $title ) {
                        $key = $title->getPrefixedDBkey();
                        $this->updates['purgeWebCache'][ $key ] = $title;
@@ -35,8 +36,9 @@
 
        /**
         * @param Title[] $titles
+        * @param array $rootJobParams
         */
-       public function scheduleRefreshLinks( array $titles ) {
+       public function scheduleRefreshLinks( array $titles, array 
$rootJobParams = [] ) {
                foreach ( $titles as $title ) {
                        $key = $title->getPrefixedDBkey();
                        $this->updates['scheduleRefreshLinks'][ $key ] = $title;
@@ -46,8 +48,9 @@
        /**
         * @param Title[] $titles
         * @param EntityChange $change
+        * @param array $rootJobParams
         */
-       public function injectRCRecords( array $titles, EntityChange $change ) {
+       public function injectRCRecords( array $titles, EntityChange $change, 
array $rootJobParams = [] ) {
                foreach ( $titles as $title ) {
                        $key = $title->getPrefixedDBkey();
                        $this->updates['injectRCRecord'][ $key ] = $change;
diff --git a/docs/hooks.txt b/docs/hooks.txt
index 375c603..e2543f3 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -30,7 +30,7 @@
 types and namespace IDs to be defiend.
 &$map: an associative array mapping Entity types to namespace ids.
 
-'WikibaseRebuildData': DEPRECATED. Used by rebuildAllData.
+'WikibaseRebuildData': DEPRECCATED. Used by rebuildAllData.
 $report: A closure that can be called with a string to report that messages.
 
 'WikibaseDeleteData': DEPRECATED. Used by deleteAllData.
@@ -57,10 +57,12 @@
 'WikibaseHandleChanges': Called by ChangeHandler::handleChange() to allow 
pre-processing
 of changes.
 $changes: A list of Change objects
+$rootJobParams: any relevant root job parameters to be inherited by child jobs.
 
 'WikibaseHandleChange': Called by ChangeHandler::handleChange() to allow 
alternative
 processing of changes.
 $change: A Change object
+$rootJobParams: any relevant root job parameters to be inherited by child jobs.
 
 'WikibaseClientOtherProjectsSidebar' Called by OtherProjectsSidebarGenerator 
to allow altering
 the other projects sidebar. Only called in case the page we're on is linked 
with an item.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I566d2253080a0e8fb74526f33763d23f7ecdadcf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
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