Reedy has uploaded a new change for review.

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

Change subject: Batch lookup of user ids rather than select per update
......................................................................

Batch lookup of user ids rather than select per update

Change-Id: Ie1084440736cc7e728920351a5ca08ed435c50ca
---
M maintenance/populateLocalAndGlobalIds.php
1 file changed, 13 insertions(+), 4 deletions(-)


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

diff --git a/maintenance/populateLocalAndGlobalIds.php 
b/maintenance/populateLocalAndGlobalIds.php
index 3f59839..56e9841 100644
--- a/maintenance/populateLocalAndGlobalIds.php
+++ b/maintenance/populateLocalAndGlobalIds.php
@@ -38,13 +38,22 @@
                                        __METHOD__,
                                        [ 'LIMIT' => $this->mBatchSize, 'ORDER 
BY' => 'gu_id ASC' ]
                                );
+                               $userList = [];
                                foreach ( $rows as $row ) {
-                                       $globalId = $row->gu_id; // Save this 
so we know where to fetch our next batch from
-                                       $localId = $ldbr->selectField( 'user', 
'user_id', [ 'user_name' => $row->lu_name ] );
+                                       $userList[$row->gu_id] = $row->lu_name;
+                               }
+
+                               $userMappings = [];
+                               $localIds = $ldbr->select( 'user', [ 'user_id', 
'user_name' ], [ 'user_name' => array_values( $userList ) ] );
+                               foreach ( $localIds as $lid ) {
+                                       $userMappings[$lid->user_name] = 
$lid->user_id;
+                               }
+                               foreach ( $userList as $id => $name ) {
+                                       $globalId = $id; // Save this so we 
know where to fetch our next batch from
                                        $result = $dbw->update(
                                                'localuser',
-                                               [ 'lu_local_id' => $localId, 
'lu_global_id' => $row->gu_id ],
-                                               [ 'lu_name' => $row->lu_name, 
'lu_wiki' => $wiki ]
+                                               [ 'lu_local_id' => 
$userMappings[$name], 'lu_global_id' => $id ],
+                                               [ 'lu_name' => $name, 'lu_wiki' 
=> $wiki ]
                                        );
                                        if ( !$result ) {
                                                $this->output( "Update failed 
for global user $globalId for wiki $wiki \n" );

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

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

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

Reply via email to