Index: trunk/extensions/Renameuser/Renameuser_body.php |
— | — | @@ -425,13 +425,14 @@ |
426 | 426 | * Do the rename operation |
427 | 427 | */ |
428 | 428 | function rename() { |
429 | | - global $wgMemc, $wgAuth; |
| 429 | + global $wgMemc, $wgAuth, $wgUpdateRowsPerJob; |
430 | 430 | |
431 | 431 | wfProfileIn( __METHOD__ ); |
432 | 432 | |
| 433 | + $dbw = wfGetDB( DB_MASTER ); |
| 434 | + $dbw->begin(); |
433 | 435 | wfRunHooks( 'RenameUserPreRename', array( $this->uid, $this->old, $this->new ) ); |
434 | 436 | |
435 | | - $dbw = wfGetDB( DB_MASTER ); |
436 | 437 | // Rename and touch the user before re-attributing edits, |
437 | 438 | // this avoids users still being logged in and making new edits while |
438 | 439 | // being renamed, which leaves edits at the old name. |
— | — | @@ -450,7 +451,6 @@ |
451 | 452 | $authUser->resetAuthToken(); |
452 | 453 | |
453 | 454 | // Delete from memcached. |
454 | | - global $wgMemc; |
455 | 455 | $wgMemc->delete( wfMemcKey( 'user', 'id', $this->uid ) ); |
456 | 456 | |
457 | 457 | // Update ipblock list if this user has a block in there. |
— | — | @@ -486,6 +486,7 @@ |
487 | 487 | wfRestoreWarnings(); |
488 | 488 | } |
489 | 489 | |
| 490 | + $jobs = array(); // jobs for all tables |
490 | 491 | // Construct jobqueue updates... |
491 | 492 | // FIXME: if a bureaucrat renames a user in error, he/she |
492 | 493 | // must be careful to wait until the rename finishes before |
— | — | @@ -505,11 +506,6 @@ |
506 | 507 | array( 'ORDER BY' => "$timestampC ASC" ) |
507 | 508 | ); |
508 | 509 | |
509 | | - global $wgUpdateRowsPerJob; |
510 | | - |
511 | | - $batchSize = 500; // Lets not flood the job table! |
512 | | - $jobSize = $wgUpdateRowsPerJob; // How many rows per job? |
513 | | - |
514 | 510 | $jobParams = array(); |
515 | 511 | $jobParams['table'] = $table; |
516 | 512 | $jobParams['column'] = $userTextC; |
— | — | @@ -523,59 +519,45 @@ |
524 | 520 | $jobParams['maxTimestamp'] = '0'; |
525 | 521 | $jobParams['count'] = 0; |
526 | 522 | |
527 | | - // Insert into queue! |
528 | | - $jobRows = 0; |
529 | | - $done = false; |
530 | | - while ( !$done ) { |
531 | | - $jobs = array(); |
532 | | - for ( $i = 0; $i < $batchSize; $i++ ) { |
533 | | - $row = $dbw->fetchObject( $res ); |
534 | | - if ( !$row ) { |
535 | | - # If there are any job rows left, add it to the queue as one job |
536 | | - if ( $jobRows > 0 ) { |
537 | | - $jobParams['count'] = $jobRows; |
538 | | - $jobs[] = Job::factory( 'renameUser', $oldTitle, $jobParams ); |
539 | | - $jobParams['minTimestamp'] = '0'; |
540 | | - $jobParams['maxTimestamp'] = '0'; |
541 | | - $jobParams['count'] = 0; |
542 | | - $jobRows = 0; |
543 | | - } |
544 | | - $done = true; |
545 | | - break; |
546 | | - } |
547 | | - # If we are adding the first item, since the ORDER BY is ASC, set |
548 | | - # the min timestamp |
549 | | - if ( $jobRows == 0 ) { |
550 | | - $jobParams['minTimestamp'] = $row->$timestampC; |
551 | | - } |
552 | | - # Keep updating the last timestamp, so it should be correct when the last item is added. |
553 | | - $jobParams['maxTimestamp'] = $row->$timestampC; |
554 | | - # Update nice counter |
555 | | - $jobRows++; |
556 | | - # Once a job has $jobSize rows, add it to the queue |
557 | | - if ( $jobRows >= $jobSize ) { |
558 | | - $jobParams['count'] = $jobRows; |
| 523 | + // Insert jobs into queue! |
| 524 | + while ( true ) { |
| 525 | + $row = $dbw->fetchObject( $res ); |
| 526 | + if ( !$row ) { |
| 527 | + # If there are any job rows left, add it to the queue as one job |
| 528 | + if ( $jobParams['count'] > 0 ) { |
559 | 529 | $jobs[] = Job::factory( 'renameUser', $oldTitle, $jobParams ); |
560 | | - $jobParams['minTimestamp'] = '0'; |
561 | | - $jobParams['maxTimestamp'] = '0'; |
562 | | - $jobParams['count'] = 0; |
563 | | - $jobRows = 0; |
564 | 530 | } |
| 531 | + break; |
565 | 532 | } |
566 | | - // FIXME: this commits per 50 rows, so when this times out |
567 | | - // (which it does) the DB will be in a half-assed state... |
568 | | - Job::batchInsert( $jobs ); |
| 533 | + # Since the ORDER BY is ASC, set the min timestamp with first row |
| 534 | + if ( $jobParams['count'] == 0 ) { |
| 535 | + $jobParams['minTimestamp'] = $row->$timestampC; |
| 536 | + } |
| 537 | + # Keep updating the last timestamp, so it should be correct |
| 538 | + # when the last item is added. |
| 539 | + $jobParams['maxTimestamp'] = $row->$timestampC; |
| 540 | + # Update row counter |
| 541 | + $jobParams['count']++; |
| 542 | + # Once a job has $wgUpdateRowsPerJob rows, add it to the queue |
| 543 | + if ( $jobParams['count'] >= $wgUpdateRowsPerJob ) { |
| 544 | + $jobs[] = Job::factory( 'renameUser', $oldTitle, $jobParams ); |
| 545 | + $jobParams['minTimestamp'] = '0'; |
| 546 | + $jobParams['maxTimestamp'] = '0'; |
| 547 | + $jobParams['count'] = 0; |
| 548 | + } |
569 | 549 | } |
570 | 550 | $dbw->freeResult( $res ); |
571 | 551 | } |
| 552 | + // @FIXME: batchInsert() commits per 50 jobs, |
| 553 | + // which sucks if the DB is rolled-back... |
| 554 | + if ( count( $jobs ) > 0 ) { |
| 555 | + Job::batchInsert( $jobs ); |
| 556 | + } |
572 | 557 | |
573 | | - // Commit the transaction |
574 | | - // FIXME: this line is misleading and nearly totally |
575 | | - // useless if the jobqueue was used for any of the tables... |
| 558 | + // Commit the transaction (though batchInsert() above commits) |
576 | 559 | $dbw->commit(); |
577 | 560 | |
578 | 561 | // Delete from memcached again to make sure |
579 | | - global $wgMemc; |
580 | 562 | $wgMemc->delete( wfMemcKey( 'user', 'id', $this->uid ) ); |
581 | 563 | |
582 | 564 | // Clear caches and inform authentication plugins |