Index: trunk/extensions/CentralAuth/migratePass0.php |
— | — | @@ -14,9 +14,11 @@ |
15 | 15 | */ |
16 | 16 | function migratePassZero() { |
17 | 17 | global $wgDBname; |
18 | | - $dbr = wfGetDB( DB_SLAVE ); // fixme for large dbs |
| 18 | + $dbr = wfGetDB( DB_SLAVE ); |
| 19 | + $chunkSize = 1000; |
19 | 20 | |
20 | 21 | $start = microtime( true ); |
| 22 | + $migrated = 0; |
21 | 23 | |
22 | 24 | // We're going to run two queries side-by-side here. |
23 | 25 | // The first fetches user data from 'user' |
— | — | @@ -26,37 +28,37 @@ |
27 | 29 | // central authentication server, which in theory might be |
28 | 30 | // on another continent. |
29 | 31 | |
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; |
53 | 55 | } |
| 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 ); |
54 | 62 | } |
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 ); |
61 | 63 | } |
62 | 64 | |
63 | 65 | function getEditCount( $userId ) { |