23 use Wikimedia\Assert\Assert;
38 if ( !$user->
getId() ) {
39 throw new RuntimeException(
"Got user ID of zero" );
42 $user->
getId() => [
'increment' => $increment,
'instances' => [ $user ] ]
48 Assert::parameterType( __CLASS__, $update,
'$update' );
49 '@phan-var UserEditCountUpdate $update';
51 foreach ( $update->infoByUser as $userId => $info ) {
52 if ( !isset( $this->infoByUser[$userId] ) ) {
53 $this->infoByUser[$userId] = [
'increment' => 0,
'instances' => [] ];
56 $this->infoByUser[$userId][
'increment'] += $info[
'increment'];
58 foreach ( $info[
'instances'] as $user ) {
59 if ( !in_array( $user, $this->infoByUser[$userId][
'instances'],
true ) ) {
60 $this->infoByUser[$userId][
'instances'][] = $user;
70 $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
71 $dbw = $lb->getConnectionRef(
DB_MASTER );
74 (
new AutoCommitUpdate( $dbw, __METHOD__,
function () use ( $lb, $dbw, $fname ) {
75 foreach ( $this->infoByUser as $userId => $info ) {
78 [
'user_editcount=user_editcount+' . (
int)$info[
'increment'] ],
79 [
'user_id' => $userId,
'user_editcount IS NOT NULL' ],
83 $affectedInstances = $info[
'instances'];
85 if ( $dbw->affectedRows() == 0 ) {
92 $dbr->flushSnapshot( $fname );
93 $lb->waitForMasterPos(
$dbr );
94 $affectedInstances[0]->initEditCountInternal(
$dbr );
96 $newCount = (int)$dbw->selectField(
99 [
'user_id' => $userId ],
106 foreach ( $affectedInstances as $affectedInstance ) {
107 $affectedInstance->setEditCountInternal( $newCount );
110 $affectedInstances[0]->invalidateCache();