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
This commit is contained in:
Kunal Mehta 2016-03-03 21:48:01 -08:00
parent f808909c67
commit 8d99490108

View file

@ -461,15 +461,22 @@ class EchoHooks {
// This edit hasn't been added to the edit count yet // This edit hasn't been added to the edit count yet
$editCount = $user->getEditCount() + 1; $editCount = $user->getEditCount() + 1;
if ( in_array( $editCount, $thresholds ) ) { if ( in_array( $editCount, $thresholds ) ) {
LoggerFactory::getInstance( 'Echo' )->debug( $id = $user->getId();
'Thanking {user} (id: {id}) for their {count} edit', DeferredUpdates::addCallableUpdate( function () use ( $id, $title, $editCount ) {
array( // Fresh User object
'user' => $user->getName(), $user = User::newFromId( $id );
'id' => $user->getId(), if ( $user->getEditCount() !== $editCount ) {
'count' => $editCount, // Race condition with multiple simultaneous requests, skip
) return;
); }
DeferredUpdates::addCallableUpdate( function () use ( $user, $title, $editCount ) { LoggerFactory::getInstance( 'Echo' )->debug(
'Thanking {user} (id: {id}) for their {count} edit',
array(
'user' => $user->getName(),
'id' => $user->getId(),
'count' => $editCount,
)
);
EchoEvent::create( array( EchoEvent::create( array(
'type' => 'thank-you-edit', 'type' => 'thank-you-edit',
'title' => $title, 'title' => $title,