Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/324840

Change subject: Cleanup InitImageData
......................................................................

Cleanup InitImageData

* Use standard --batch-size parameter
* Added --start parameter
* Use MediaWikiServices

Change-Id: I5828db7b9fb7ba12eeb3ce3313c4fe7e7926c916
---
M maintenance/initImageData.php
1 file changed, 12 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageImages 
refs/changes/40/324840/1

diff --git a/maintenance/initImageData.php b/maintenance/initImageData.php
index b87b1e5..9f2af9e 100644
--- a/maintenance/initImageData.php
+++ b/maintenance/initImageData.php
@@ -6,24 +6,29 @@
 }
 require_once( "$IP/maintenance/Maintenance.php" );
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * @license WTFPL 2.0
  * @author Max Semenik
  */
 class InitImageData extends Maintenance {
-       const BATCH_SIZE = 100;
-
        public function __construct() {
                parent::__construct();
                $this->mDescription = 'Initializes PageImages data';
-               $this->addOption( 'namespaces', 'Comma-separated list of 
namespace(s) to refresh', false, true );
-               $this->addOption( 'earlier-than', 'Run only on pages earlier 
than this timestamp', false, true );
+               $this->addOption( 'namespaces',
+                       'Comma-separated list of namespace(s) to refresh', 
false, true );
+               $this->addOption( 'earlier-than',
+                       'Run only on pages earlier than this timestamp', false, 
true );
+               $this->addOption( 'start', 'Starting page ID', false, true );
+               $this->setBatchSize( 100 );
        }
 
        public function execute() {
                global $wgPageImagesNamespaces;
 
-               $id = 0;
+               $id = $this->getOption( 'start', 0 );
+               $lbFactory = 
MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
 
                do {
                        $tables = array( 'page', 'imagelinks' );
@@ -49,13 +54,13 @@
                                        . $dbr->addQuotes( $this->getOption( 
'earlier-than' ) );
                        }
                        $res = $dbr->select( $tables, $fields, $conds, 
__METHOD__,
-                               array( 'LIMIT' => self::BATCH_SIZE, 'ORDER_BY' 
=> 'page_id', 'GROUP BY' => 'page_id' ),
+                               [ 'LIMIT' => $this->mBatchSize, 'ORDER_BY' => 
'page_id', 'GROUP BY' => 'page_id' ],
                                $joinConds
                        );
                        foreach ( $res as $row ) {
                                $id = $row->page_id;
                                RefreshLinks::fixLinksFromArticle( $id );
-                               wfWaitForSlaves();
+                               $lbFactory->waitForReplication();
                        }
                        $this->output( "$id\n" );
                } while ( $res->numRows() );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5828db7b9fb7ba12eeb3ce3313c4fe7e7926c916
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageImages
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

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

Reply via email to