X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_del%27%2C%20idvote=vote.voteid%29%20%7D%7D?a=blobdiff_plain;f=includes%2Fdeferred%2FUserEditCountUpdate.php;h=5194e4f1cc24ea9237fe02bb5acce4b74b097458;hb=e2088f1170b2867ca3ababe205137cc6ad010068;hp=2a1205c675a0d5927a0e71d62458cf4dbb5b1de5;hpb=15f41ebeac0fa76ccf4cdd76d93e7308a30d3f10;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/deferred/UserEditCountUpdate.php b/includes/deferred/UserEditCountUpdate.php index 2a1205c675..5194e4f1cc 100644 --- a/includes/deferred/UserEditCountUpdate.php +++ b/includes/deferred/UserEditCountUpdate.php @@ -66,48 +66,48 @@ class UserEditCountUpdate implements DeferrableUpdate, MergeableUpdate { * Purges the list of URLs passed to the constructor. */ public function doUpdate() { - foreach ( $this->infoByUser as $userId => $info ) { - $lb = MediaWikiServices::getInstance()->getDBLoadBalancer(); - $dbw = $lb->getConnection( DB_MASTER ); + $lb = MediaWikiServices::getInstance()->getDBLoadBalancer(); + $dbw = $lb->getConnection( DB_MASTER ); - $dbw->startAtomic( __METHOD__ ); // define minimum row lock duration - $dbw->update( - 'user', - [ 'user_editcount=user_editcount+' . (int)$info['increment'] ], - [ 'user_id' => $userId, 'user_editcount IS NOT NULL' ], - __METHOD__ - ); - /** @var User[] $affectedInstances */ - $affectedInstances = $info['instances']; - // Lazy initialization check... - if ( $dbw->affectedRows() == 0 ) { - // No rows will be "affected" if user_editcount is NULL. - // Get the generic "replica" connection to see if it actually uses the master. - $dbr = $lb->getConnection( DB_REPLICA ); - if ( $dbr !== $dbw ) { - // This method runs after the new revisions were committed. - // Wait for the replica to catch up so they will all be counted. - $dbr->flushSnapshot( __METHOD__ ); - $lb->safeWaitForMasterPos( $dbr ); + ( new AutoCommitUpdate( $dbw, __METHOD__, function () use ( $lb, $dbw ) { + foreach ( $this->infoByUser as $userId => $info ) { + $dbw->update( + 'user', + [ 'user_editcount=user_editcount+' . (int)$info['increment'] ], + [ 'user_id' => $userId, 'user_editcount IS NOT NULL' ], + __METHOD__ + ); + /** @var User[] $affectedInstances */ + $affectedInstances = $info['instances']; + // Lazy initialization check... + if ( $dbw->affectedRows() == 0 ) { + // No rows will be "affected" if user_editcount is NULL. + // Check if the generic "replica" connection is not the master. + $dbr = $lb->getConnection( DB_REPLICA ); + if ( $dbr !== $dbw ) { + // This method runs after the new revisions were committed. + // Wait for the replica to catch up so they will all be counted. + $dbr->flushSnapshot( __METHOD__ ); + $lb->safeWaitForMasterPos( $dbr ); + } + $affectedInstances[0]->initEditCountInternal(); } - $affectedInstances[0]->initEditCountInternal(); - } - $newCount = (int)$dbw->selectField( - 'user', - [ 'user_editcount' ], - [ 'user_id' => $userId ], - __METHOD__ - ); - $dbw->endAtomic( __METHOD__ ); + $newCount = (int)$dbw->selectField( + 'user', + [ 'user_editcount' ], + [ 'user_id' => $userId ], + __METHOD__ + ); - // Update the edit count in the instance caches. This is mostly useful - // for maintenance scripts, where deferred updates might run immediately - // and user instances might be reused for a long time. - foreach ( $affectedInstances as $affectedInstance ) { - $affectedInstance->setEditCountInternal( $newCount ); + // Update the edit count in the instance caches. This is mostly useful + // for maintenance scripts, where deferred updates might run immediately + // and user instances might be reused for a long time. + foreach ( $affectedInstances as $affectedInstance ) { + $affectedInstance->setEditCountInternal( $newCount ); + } + // Clear the edit count in user cache too + $affectedInstances[0]->invalidateCache(); } - // Clear the edit count in user cache too - $affectedInstances[0]->invalidateCache(); - } + } ) )->doUpdate(); } }