Catrope has uploaded a new change for review.
https://gerrit.wikimedia.org/r/274908
Change subject: Try and avoid race conditions with thank-you-edit notifications
......................................................................
Try and avoid race conditions with thank-you-edit notifications
Wait until after the main transaction has been committed before checking
whether they have the right number of edits.
Bug: T128249
Change-Id: I38cc0f96e97fda3692340cc8906144a002594ef2
(cherry picked from commit 8d9949010813cf5f31ca6ba0c638ca25ed815bf2)
---
M Hooks.php
1 file changed, 16 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/08/274908/1
diff --git a/Hooks.php b/Hooks.php
index 0b67aa1..b326795 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -461,15 +461,22 @@
// This edit hasn't been added to the edit count yet
$editCount = $user->getEditCount() + 1;
if ( in_array( $editCount, $thresholds ) ) {
- LoggerFactory::getInstance( 'Echo' )->debug(
- 'Thanking {user} (id: {id}) for their
{count} edit',
- array(
- 'user' => $user->getName(),
- 'id' => $user->getId(),
- 'count' => $editCount,
- )
- );
- DeferredUpdates::addCallableUpdate( function ()
use ( $user, $title, $editCount ) {
+ $id = $user->getId();
+ DeferredUpdates::addCallableUpdate( function ()
use ( $id, $title, $editCount ) {
+ // Fresh User object
+ $user = User::newFromId( $id );
+ if ( $user->getEditCount() !==
$editCount ) {
+ // Race condition with multiple
simultaneous requests, skip
+ return;
+ }
+ LoggerFactory::getInstance( 'Echo'
)->debug(
+ 'Thanking {user} (id: {id}) for
their {count} edit',
+ array(
+ 'user' =>
$user->getName(),
+ 'id' => $user->getId(),
+ 'count' => $editCount,
+ )
+ );
EchoEvent::create( array(
'type' =>
'thank-you-edit',
'title' => $title,
--
To view, visit https://gerrit.wikimedia.org/r/274908
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I38cc0f96e97fda3692340cc8906144a002594ef2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: wmf/1.27.0-wmf.15
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits