Krinkle has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/394400 )
Change subject: jobs: Remove ClearUserWatchlistJob 'batchSize' option
......................................................................
jobs: Remove ClearUserWatchlistJob 'batchSize' option
Use $wgUpdateRowsPerQuery instead, and use its value at run-time
instead of inside the job parameters. Also helps with deduplication
if batchSize is changed.
Change-Id: Ifef25a3ae5ae2418359a41eba05778613fbb548f
---
M includes/jobqueue/jobs/ClearUserWatchlistJob.php
M tests/phpunit/includes/jobqueue/jobs/ClearUserWatchlistJobTest.php
2 files changed, 8 insertions(+), 8 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/00/394400/1
diff --git a/includes/jobqueue/jobs/ClearUserWatchlistJob.php
b/includes/jobqueue/jobs/ClearUserWatchlistJob.php
index 17c4b66..3e8b2ad 100644
--- a/includes/jobqueue/jobs/ClearUserWatchlistJob.php
+++ b/includes/jobqueue/jobs/ClearUserWatchlistJob.php
@@ -28,15 +28,10 @@
/**
* @param Title|null $title Not used by this job.
* @param array $params
- * - batchSize, Number of watchlist entries to remove at once.
* - userId, The ID for the user whose watchlist is being
cleared.
* - maxWatchlistId, The maximum wl_id at the time the job was first
created,
*/
public function __construct( Title $title = null, array $params ) {
- if ( !array_key_exists( 'batchSize', $params ) ) {
- $params['batchSize'] = 1000;
- }
-
parent::__construct(
'clearUserWatchlist',
SpecialPage::getTitleFor( 'EditWatchlist', 'clear' ),
@@ -47,8 +42,10 @@
}
public function run() {
+ global $wgUpdateRowsPerQuery;
$userId = $this->params['userId'];
$maxWatchlistId = $this->params['maxWatchlistId'];
+ $batchSize = $wgUpdateRowsPerQuery;
$loadBalancer =
MediaWikiServices::getInstance()->getDBLoadBalancer();
$dbw = $loadBalancer->getConnection( DB_MASTER );
@@ -86,7 +83,7 @@
__METHOD__,
[
'ORDER BY' => 'wl_id ASC',
- 'LIMIT' => $this->params['batchSize'],
+ 'LIMIT' => $batchSize,
]
);
@@ -101,7 +98,9 @@
$lbf->commitMasterChanges( __METHOD__ );
unset( $scopedLock );
- if ( count( $watchlistIds ) == $this->params['batchSize'] ) {
+ if ( count( $watchlistIds ) === (int)$batchSize ) {
+ // Until we get less results than the limit,
recursively push
+ // the same job again.
JobQueueGroup::singleton()->push( new self(
$this->getTitle(), $this->getParams() ) );
}
diff --git a/tests/phpunit/includes/jobqueue/jobs/ClearUserWatchlistJobTest.php
b/tests/phpunit/includes/jobqueue/jobs/ClearUserWatchlistJobTest.php
index 385ecb7..b5257a3 100644
--- a/tests/phpunit/includes/jobqueue/jobs/ClearUserWatchlistJobTest.php
+++ b/tests/phpunit/includes/jobqueue/jobs/ClearUserWatchlistJobTest.php
@@ -48,12 +48,13 @@
$watchedItemStore->addWatch( $user, new TitleValue( 0, 'C' ) );
$watchedItemStore->addWatch( $user, new TitleValue( 1, 'C' ) );
+ $this->setMwGlobals( 'wgUpdateRowsPerQuery', 2 );
+
JobQueueGroup::singleton()->push(
new ClearUserWatchlistJob(
null,
[
'userId' => $user->getId(),
- 'batchSize' => 2,
'maxWatchlistId' => $maxId,
]
)
--
To view, visit https://gerrit.wikimedia.org/r/394400
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifef25a3ae5ae2418359a41eba05778613fbb548f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits