Aude has uploaded a new change for review. https://gerrit.wikimedia.org/r/207371
Change subject: Add some (optional) verbosity to ChangesSubscriptionTableBuilder ...................................................................... Add some (optional) verbosity to ChangesSubscriptionTableBuilder Some additional verbosity can be helpful, plus timestamps on the script output in case of problems with running the script. Change-Id: I7f2e160f3c833c6e268c707b3bc05c373d237301 (cherry picked from commit 78899f4d8d797adabcb5a16461ebe07753323a1c) --- M repo/includes/store/sql/ChangesSubscriptionTableBuilder.php M repo/maintenance/populateChangesSubscription.php M repo/tests/phpunit/includes/store/sql/ChangesSubscriptionTableBuilderTest.php 3 files changed, 45 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/71/207371/1 diff --git a/repo/includes/store/sql/ChangesSubscriptionTableBuilder.php b/repo/includes/store/sql/ChangesSubscriptionTableBuilder.php index 3e1472b..ceaca5e 100644 --- a/repo/includes/store/sql/ChangesSubscriptionTableBuilder.php +++ b/repo/includes/store/sql/ChangesSubscriptionTableBuilder.php @@ -43,13 +43,24 @@ private $progressReporter; /** + * @var string 'verbose' or 'standard' + */ + private $verbosity; + + /** * @param LoadBalancer $loadBalancer * @param string $tableName * @param int $batchSize + * @param string $verbosity Either 'standard' or 'verbose' * * @throws InvalidArgumentException */ - public function __construct( LoadBalancer $loadBalancer, $tableName, $batchSize = 1000 ) { + public function __construct( + LoadBalancer $loadBalancer, + $tableName, + $batchSize, + $verbosity = 'standard' + ) { if ( !is_string( $tableName ) ) { throw new InvalidArgumentException( '$tableName must be a string' ); } @@ -58,9 +69,15 @@ throw new InvalidArgumentException( '$batchSize must be an integer >= 1' ); } + if ( $verbosity !== 'standard' && $verbosity !== 'verbose' ) { + throw new InvalidArgumentException( '$verbosity must be either "verbose"' + . ' or "standard".' ); + } + $this->loadBalancer = $loadBalancer; $this->tableName = $tableName; $this->batchSize = $batchSize; + $this->verbosity = $verbosity; $this->exceptionHandler = new LogWarningExceptionHandler(); $this->progressReporter = new NullMessageReporter(); @@ -157,6 +174,11 @@ ) ); + if ( $this->verbosity === 'verbose' ) { + $this->progressReporter->reportMessage( 'Inserted ' . $db->affectedRows() + . ' into wb_changes_subscription' ); + } + $c+= count( $rows ); } @@ -171,7 +193,6 @@ * @return array[] An associative array mapping item IDs to lists of site IDs. */ private function getSubscriptionsPerItemBatch( DatabaseBase $db, &$continuation = array() ) { - if ( empty( $continuation ) ) { $continuationCondition = '1'; } else { @@ -195,6 +216,11 @@ ) ); + if ( $this->verbosity === 'verbose' ) { + $this->progressReporter->reportMessage( 'Selected ' . $res->numRows() . ' wb_item_per_site records' + . ' with continuation: ' . $continuationCondition ); + } + return $this->getSubscriptionsPerItemFromRows( $res, $continuation ); } diff --git a/repo/maintenance/populateChangesSubscription.php b/repo/maintenance/populateChangesSubscription.php index 49e957c..478d650 100644 --- a/repo/maintenance/populateChangesSubscription.php +++ b/repo/maintenance/populateChangesSubscription.php @@ -26,6 +26,7 @@ $this->mDescription = 'Populate the wb_changes_subscription table based on entries in wb_items_per_site.'; $this->addOption( 'start-item', "The item ID to start from.", false, true ); + $this->addOption( 'verbose', 'Report more detailed script progress.' ); parent::__construct(); @@ -52,6 +53,8 @@ throw new EntityIdParsingException( 'Not an Item ID: ' . $startItemOption ); } + $verbose = (bool) $this->getOption( 'verbose', false ); + $reporter = new ObservableMessageReporter(); $reporter->registerReporterCallback( array( $this, 'report' ) @@ -60,7 +63,8 @@ $builder = new ChangesSubscriptionTableBuilder( wfGetLB(), 'wb_changes_subscription', - $this->mBatchSize + $this->mBatchSize, + $verbose ? 'verbose' : 'standard' ); $builder->setProgressReporter( $reporter ); @@ -85,7 +89,7 @@ * @param string $msg */ public function report( $msg ) { - $this->output( "$msg\n" ); + $this->output( date( 'H:i:s' ) . ": $msg\n" ); } } diff --git a/repo/tests/phpunit/includes/store/sql/ChangesSubscriptionTableBuilderTest.php b/repo/tests/phpunit/includes/store/sql/ChangesSubscriptionTableBuilderTest.php index efb08df..94795d1 100644 --- a/repo/tests/phpunit/includes/store/sql/ChangesSubscriptionTableBuilderTest.php +++ b/repo/tests/phpunit/includes/store/sql/ChangesSubscriptionTableBuilderTest.php @@ -40,13 +40,19 @@ /** * @param int $batchSize + * @param string $verbosity * * @return ChangesSubscriptionTableBuilder */ - private function getChangesSubscriptionTableBuilder( $batchSize = 10 ) { + private function getChangesSubscriptionTableBuilder( $batchSize, $verbosity ) { $loadBalancer = wfGetLB(); - return new ChangesSubscriptionTableBuilder( $loadBalancer, self::TABLE_NAME, $batchSize ); + return new ChangesSubscriptionTableBuilder( + $loadBalancer, + self::TABLE_NAME, + $batchSize, + $verbosity + ); } public function testFillSubscriptionTable() { @@ -58,7 +64,7 @@ array( 22, 'frwiki' ), ) ); - $primer = $this->getChangesSubscriptionTableBuilder( 3 ); + $primer = $this->getChangesSubscriptionTableBuilder( 3, 'standard' ); $primer->setProgressReporter( $this->getMessageReporter( $this->exactly( 2 ) ) ); $primer->setExceptionHandler( $this->getExceptionHandler( $this->exactly( 0 ) ) ); @@ -86,8 +92,8 @@ array( 22, 'frwiki' ), ) ); - $primer = $this->getChangesSubscriptionTableBuilder( 3 ); - $primer->setProgressReporter( $this->getMessageReporter( $this->exactly( 1 ) ) ); + $primer = $this->getChangesSubscriptionTableBuilder( 3, 'verbose' ); + $primer->setProgressReporter( $this->getMessageReporter( $this->exactly( 4 ) ) ); $primer->setExceptionHandler( $this->getExceptionHandler( $this->exactly( 0 ) ) ); $primer->fillSubscriptionTable( new ItemId( 'Q20' ) ); -- To view, visit https://gerrit.wikimedia.org/r/207371 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7f2e160f3c833c6e268c707b3bc05c373d237301 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: wmf/1.26wmf2 Gerrit-Owner: Aude <aude.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits