jenkins-bot has submitted this change and it was merged.

Change subject: thank-you-edit: Only call User::getEditCount() once
......................................................................


thank-you-edit: Only call User::getEditCount() once

And rename $editCount to $thresholdCount for clarity.

Change-Id: I115b2dfabf472c855c186d05fa4e31aa7c9c3d6c
---
M Hooks.php
1 file changed, 9 insertions(+), 8 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Hooks.php b/Hooks.php
index 59ada97..4c19644 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -459,13 +459,14 @@
                $thresholds = [ 1, 10, 100, 1000, 10000, 100000, 1000000 ];
                if ( $user->isLoggedIn() && $status->value['revision'] ) {
                        // This edit hasn't been added to the edit count yet
-                       $editCount = $user->getEditCount() + 1;
-                       if ( in_array( $editCount, $thresholds ) ) {
+                       $thresholdCount = $user->getEditCount() + 1;
+                       if ( in_array( $thresholdCount, $thresholds ) ) {
                                $id = $user->getId();
-                               DeferredUpdates::addCallableUpdate( function () 
use ( $id, $title, $editCount ) {
+                               DeferredUpdates::addCallableUpdate( function () 
use ( $id, $title, $thresholdCount ) {
                                        // Fresh User object
                                        $user = User::newFromId( $id );
-                                       if ( $user->getEditCount() !== 
$editCount ) {
+                                       $userEditCount = $user->getEditCount();
+                                       if ( $userEditCount !== $thresholdCount 
) {
                                                // Race condition with multiple 
simultaneous requests, skip
                                                LoggerFactory::getInstance( 
'Echo' )->debug(
                                                        'thank-you-edit race 
condition detected: {user} (id: {id}) should ' .
@@ -473,8 +474,8 @@
                                                        array(
                                                                'user' => 
$user->getName(),
                                                                'id' => 
$user->getId(),
-                                                               'expectedCount' 
=> $editCount,
-                                                               'actualCount' 
=> $user->getEditCount(),
+                                                               'expectedCount' 
=> $thresholdCount,
+                                                               'actualCount' 
=> $userEditCount,
                                                        )
                                                );
                                                return;
@@ -484,7 +485,7 @@
                                                array(
                                                        'user' => 
$user->getName(),
                                                        'id' => $user->getId(),
-                                                       'count' => $editCount,
+                                                       'count' => 
$thresholdCount,
                                                )
                                        );
                                        EchoEvent::create( array(
@@ -494,7 +495,7 @@
                                                        // Edit threshold 
notifications are sent to the agent
                                                        'extra' => array(
                                                                'notifyAgent' 
=> true,
-                                                               'editCount' => 
$editCount,
+                                                               
'thresholdCount' => $thresholdCount,
                                                        )
                                                )
                                        );

-- 
To view, visit https://gerrit.wikimedia.org/r/276080
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I115b2dfabf472c855c186d05fa4e31aa7c9c3d6c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to