Legoktm has uploaded a new change for review.

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

Change subject: forceRenameUsers: Pause if more than 50 renames in progress
......................................................................

forceRenameUsers: Pause if more than 50 renames in progress

Also add some extra debug logging

Change-Id: Iec109b29d731ef5b96f3ce6c5d3ed8bd0a8ac3b8
---
M maintenance/forceRenameUsers.php
1 file changed, 22 insertions(+), 2 deletions(-)


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

diff --git a/maintenance/forceRenameUsers.php b/maintenance/forceRenameUsers.php
index 0782305..e597db7 100644
--- a/maintenance/forceRenameUsers.php
+++ b/maintenance/forceRenameUsers.php
@@ -19,6 +19,7 @@
 
        public function __construct() {
                $this->mDescription = 'Forcibly renames and migrates unattached 
accounts to global ones';
+               $this->setBatchSize( 10 );
        }
 
        private function log( $msg ) {
@@ -37,15 +38,31 @@
                        foreach ( $rowsToRename as $row ) {
                                $this->rename( $row, $dbw );
                        }
-
                        CentralAuthUser::waitForSlaves();
+                       $count = $this->getCurrentRenameCount( $dbw );
+                       while ( $count > 50 ) {
+                               $this->output( "There are currently $count 
renames queued, pausing..." );
+                               sleep( 5 );
+                               $count = $this->getCurrentRenameCount( $dbw );
+                       }
                }
+       }
+
+       protected function getCurrentRenameCount( DatabaseBase $dbw ) {
+               $row = $dbw->selectRow(
+                       array( 'renameuser_status'),
+                       array( 'COUNT(*) as count' ),
+                       array(),
+                       __METHOD__
+               );
+               return (int)$row->count;
        }
 
        protected function rename( $row, DatabaseBase $dbw ) {
                $wiki = $row->utr_wiki;
                $name = $row->utr_name;
                $newNamePrefix = "$name~$wiki";
+               $this->output( "Beginning rename of $newNamePrefix" );
                $newCAUser = new CentralAuthUser( $newNamePrefix );
                $count = 0;
                // Edge case: Someone created User:Foo~wiki manually.
@@ -54,6 +71,9 @@
                while ( $newCAUser->exists() ) {
                        $count++;
                        $newCAUser = new CentralAuthUser( $newNamePrefix . 
(string)$count );
+               }
+               if ( $newNamePrefix !== $newCAUser->getName() ) {
+                       $this->output( "WARNING: New name is now 
{$newCAUser->getName()}" );
                }
                $this->log( "Renaming $name to {$newCAUser->getName()}." );
 
@@ -99,7 +119,7 @@
        protected function findUsers( $wiki, DatabaseBase $dbw ) {
                $rowsToRename = array();
                $updates = new UsersToRenameDatabaseUpdates( $dbw );
-               $rows = $updates->findUsers( $wiki, 
UsersToRenameDatabaseUpdates::NOTIFIED, 50 );
+               $rows = $updates->findUsers( $wiki, 
UsersToRenameDatabaseUpdates::NOTIFIED, $this->mBatchSize );
 
                foreach ( $rows as $row ) {
                        $caUser = new CentralAuthUser( $row->utr_name );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iec109b29d731ef5b96f3ce6c5d3ed8bd0a8ac3b8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to