X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Fincludes%2FMigrateActors.php;h=ba6c375aa7293691c30fbb2bfc2be2f060f82df9;hb=b7cd670cb7b2bf58ff4ab9db845d0bee0301b6cc;hp=ceba9b5f36469950cf614a72e29e03b5c4b20949;hpb=9eafd89011b9b031d902a4381e13254fb67e1e07;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/includes/MigrateActors.php b/maintenance/includes/MigrateActors.php index ceba9b5f36..ba6c375aa7 100644 --- a/maintenance/includes/MigrateActors.php +++ b/maintenance/includes/MigrateActors.php @@ -413,13 +413,12 @@ class MigrateActors extends LoggedUpdateMaintenance { protected function migrateLogSearch() { $complainedAboutUsers = []; - $primaryKey = [ 'ls_field', 'ls_value' ]; - $pkFilter = array_flip( $primaryKey ); + $primaryKey = [ 'ls_value', 'ls_log_id' ]; $this->output( "Beginning migration of log_search\n" ); wfWaitForSlaves(); $dbw = $this->getDB( DB_MASTER ); - $countUpdated = 0; + $countInserted = 0; $countActors = 0; $countErrors = 0; @@ -427,72 +426,44 @@ class MigrateActors extends LoggedUpdateMaintenance { while ( true ) { // Fetch the rows needing update $res = $dbw->select( + [ 'log_search', 'actor' ], + [ 'ls_value', 'ls_log_id', 'actor_id' ], [ - 'ls' => $dbw->buildSelectSubquery( - 'log_search', - 'ls_value', - [ - 'ls_field' => 'target_author_id', - $next - ], - __METHOD__, - [ - 'DISTINCT', - 'ORDER BY' => [ 'ls_value' ], - 'LIMIT' => $this->mBatchSize, - ] - ), - 'actor' + 'ls_field' => 'target_author_id', + $next ], + __METHOD__, [ - 'ls_field' => $dbw->addQuotes( 'target_author_id' ), - 'ls_value', - 'actor_id' + 'ORDER BY' => $primaryKey, + 'LIMIT' => $this->mBatchSize, ], - [], - __METHOD__, - [], [ 'actor' => [ 'LEFT JOIN', 'ls_value = ' . $dbw->buildStringCast( 'actor_user' ) ] ] ); if ( !$res->numRows() ) { break; } - // Update the rows - $del = []; + // Insert a 'target_author_actor' for each 'target_author_id' + $ins = []; foreach ( $res as $row ) { $lastRow = $row; if ( !$row->actor_id ) { list( , $display ) = $this->makeNextCond( $dbw, $primaryKey, $row ); - $this->error( "No actor for row with $display\n" ); + $this->error( "No actor for target_author_id row with $display\n" ); $countErrors++; continue; } - $dbw->update( - 'log_search', - [ - 'ls_field' => 'target_author_actor', - 'ls_value' => $row->actor_id, - ], - [ - 'ls_field' => $row->ls_field, - 'ls_value' => $row->ls_value, - ], - __METHOD__, - [ 'IGNORE' ] - ); - $countUpdated += $dbw->affectedRows(); - $del[] = $row->ls_value; - } - if ( $del ) { - $dbw->delete( - 'log_search', [ 'ls_field' => 'target_author_id', 'ls_value' => $del ], __METHOD__ - ); - $countUpdated += $dbw->affectedRows(); + $ins[] = [ + 'ls_field' => 'target_author_actor', + 'ls_value' => $row->actor_id, + 'ls_log_id' => $row->ls_log_id, + ]; } + $dbw->insert( 'log_search', $ins, __METHOD__, [ 'IGNORE' ] ); + $countInserted += $dbw->affectedRows(); list( $next, $display ) = $this->makeNextCond( $dbw, $primaryKey, $lastRow ); - $this->output( "... $display\n" ); + $this->output( "... target_author_id, $display\n" ); wfWaitForSlaves(); } @@ -500,31 +471,17 @@ class MigrateActors extends LoggedUpdateMaintenance { while ( true ) { // Fetch the rows needing update $res = $dbw->select( + [ 'log_search', 'actor' ], + [ 'ls_value', 'ls_log_id', 'actor_id' ], [ - 'ls' => $dbw->buildSelectSubquery( - 'log_search', - 'ls_value', - [ - 'ls_field' => 'target_author_ip', - $next - ], - __METHOD__, - [ - 'DISTINCT', - 'ORDER BY' => [ 'ls_value' ], - 'LIMIT' => $this->mBatchSize, - ] - ), - 'actor' + 'ls_field' => 'target_author_ip', + $next ], + __METHOD__, [ - 'ls_field' => $dbw->addQuotes( 'target_author_ip' ), - 'ls_value', - 'actor_id' + 'ORDER BY' => $primaryKey, + 'LIMIT' => $this->mBatchSize, ], - [], - __METHOD__, - [], [ 'actor' => [ 'LEFT JOIN', 'ls_value = actor_name' ] ] ); if ( !$res->numRows() ) { @@ -538,45 +495,31 @@ class MigrateActors extends LoggedUpdateMaintenance { $dbw, 'ls_value', $rows, $complainedAboutUsers, $countErrors ); - // Update the rows - $del = []; + // Insert a 'target_author_actor' for each 'target_author_ip' + $ins = []; foreach ( $rows as $row ) { if ( !$row->actor_id ) { list( , $display ) = $this->makeNextCond( $dbw, $primaryKey, $row ); - $this->error( "Could not make actor for row with $display\n" ); + $this->error( "Could not make actor for target_author_ip row with $display\n" ); $countErrors++; continue; } - $dbw->update( - 'log_search', - [ - 'ls_field' => 'target_author_actor', - 'ls_value' => $row->actor_id, - ], - [ - 'ls_field' => $row->ls_field, - 'ls_value' => $row->ls_value, - ], - __METHOD__, - [ 'IGNORE' ] - ); - $countUpdated += $dbw->affectedRows(); - $del[] = $row->ls_value; - } - if ( $del ) { - $dbw->delete( - 'log_search', [ 'ls_field' => 'target_author_ip', 'ls_value' => $del ], __METHOD__ - ); - $countUpdated += $dbw->affectedRows(); + $ins[] = [ + 'ls_field' => 'target_author_actor', + 'ls_value' => $row->actor_id, + 'ls_log_id' => $row->ls_log_id, + ]; } + $dbw->insert( 'log_search', $ins, __METHOD__, [ 'IGNORE' ] ); + $countInserted += $dbw->affectedRows(); list( $next, $display ) = $this->makeNextCond( $dbw, $primaryKey, $lastRow ); - $this->output( "... $display\n" ); + $this->output( "... target_author_ip, $display\n" ); wfWaitForSlaves(); } $this->output( - "Completed migration, updated $countUpdated row(s) with $countActors new actor(s), " + "Completed migration, inserted $countInserted row(s) with $countActors new actor(s), " . "$countErrors error(s)\n" ); return $countErrors;