r17975 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17974‎ | r17975 | r17976 >
Date:07:44, 28 November 2006
Author:brion
Status:old
Tags:
Comment:
* run user table input in chunks to be nicer to the poor database
* provide input percentage feedback
Modified paths:
  • /trunk/extensions/CentralAuth/migratePass0.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralAuth/migratePass0.php
@@ -14,9 +14,11 @@
1515 */
1616 function migratePassZero() {
1717 global $wgDBname;
18 - $dbr = wfGetDB( DB_SLAVE ); // fixme for large dbs
 18+ $dbr = wfGetDB( DB_SLAVE );
 19+ $chunkSize = 1000;
1920
2021 $start = microtime( true );
 22+ $migrated = 0;
2123
2224 // We're going to run two queries side-by-side here.
2325 // The first fetches user data from 'user'
@@ -26,37 +28,37 @@
2729 // central authentication server, which in theory might be
2830 // on another continent.
2931
30 - $user = $dbr->tableName( 'user' );
31 - $revision = $dbr->tableName( 'revision' );
32 - $result = $dbr->query(
33 - "SELECT
34 - user_id,
35 - user_name,
36 - user_password,
37 - user_newpassword,
38 - user_email,
39 - user_email_authenticated,
40 - COUNT(rev_user) AS user_editcount
41 - FROM $user
42 - LEFT OUTER JOIN $revision ON user_id=rev_user
43 - GROUP BY user_id" );
44 -
45 - $migrated = 0;
46 - while( $row = $dbr->fetchObject( $result ) ) {
47 - CentralAuthUser::storeLocalData( $wgDBname, $row, $row->user_editcount );
48 - if( ++$migrated % 100 == 0 ) {
49 - $delta = microtime( true ) - $start;
50 - $rate = ($delta == 0.0) ? 0.0 : $migrated / $delta;
51 - printf( "%d done in %0.1f secs (%0.3f accounts/sec).\n",
52 - $migrated, $delta, $rate );
 32+ $lastUser = $dbr->selectField( 'user', 'MAX(user_id)', '', __FUNCTION__ );
 33+ for( $min = 0; $min <= $lastUser; $min += $chunkSize ) {
 34+ $max = $min + $chunkSize;
 35+ $user = $dbr->tableName( 'user' );
 36+ $revision = $dbr->tableName( 'revision' );
 37+ $result = $dbr->query(
 38+ "SELECT
 39+ user_id,
 40+ user_name,
 41+ user_password,
 42+ user_newpassword,
 43+ user_email,
 44+ user_email_authenticated,
 45+ COUNT(rev_user) AS user_editcount
 46+ FROM $user
 47+ LEFT OUTER JOIN $revision ON user_id=rev_user
 48+ WHERE user_id > $min AND user_id <= $max
 49+ GROUP BY user_id",
 50+ __FUNCTION__ );
 51+
 52+ while( $row = $dbr->fetchObject( $result ) ) {
 53+ CentralAuthUser::storeLocalData( $wgDBname, $row, $row->user_editcount );
 54+ ++$migrated;
5355 }
 56+ $dbr->freeResult( $result );
 57+
 58+ $delta = microtime( true ) - $start;
 59+ $rate = ($delta == 0.0) ? 0.0 : $migrated / $delta;
 60+ printf( "%d (%0.1f%%) done in %0.1f secs (%0.3f accounts/sec).\n",
 61+ $migrated, $migrated / $lastUser * 100.0, $delta, $rate );
5462 }
55 - $dbr->freeResult( $result );
56 -
57 - $delta = microtime( true ) - $start;
58 - $rate = ($delta == 0.0) ? 0.0 : $migrated / $delta;
59 - printf( "%d done in %0.1f secs (%0.3f accounts/sec).\n",
60 - $migrated, $delta, $rate );
6163 }
6264
6365 function getEditCount( $userId ) {