Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/203987

Change subject: Avoid deadlocks in User::incEditCount
......................................................................

Avoid deadlocks in User::incEditCount

Change-Id: I930222d5e831bb3729194abbdcb3cab194c70494
---
M includes/User.php
1 file changed, 14 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/87/203987/1

diff --git a/includes/User.php b/includes/User.php
index f526fe0..18c2ed8 100644
--- a/includes/User.php
+++ b/includes/User.php
@@ -4742,34 +4742,24 @@
         * Will have no effect for anonymous users.
         */
        public function incEditCount() {
-               if ( !$this->isAnon() ) {
-                       $dbw = wfGetDB( DB_MASTER );
+               if ( $this->isAnon() ) {
+                       return;
+               }
+
+               $dbw = wfGetDB( DB_MASTER );
+
+               $that = $this;
+               $fname = __METHOD__;
+               $dbw->onTransactionPreCommitOrIdle( function() use ( $dbw, 
$that, $fname ) {
                        $dbw->update(
                                'user',
                                array( 'user_editcount=user_editcount+1' ),
-                               array( 'user_id' => $this->getId() ),
-                               __METHOD__
+                               array( 'user_id' => $that->getId() ),
+                               $fname
                        );
-
-                       // Lazy initialization check...
-                       if ( $dbw->affectedRows() == 0 ) {
-                               // Now here's a goddamn hack...
-                               $dbr = wfGetDB( DB_SLAVE );
-                               if ( $dbr !== $dbw ) {
-                                       // If we actually have a slave server, 
the count is
-                                       // at least one behind because the 
current transaction
-                                       // has not been committed and 
replicated.
-                                       $this->initEditCount( 1 );
-                               } else {
-                                       // But if DB_SLAVE is selecting the 
master, then the
-                                       // count we just read includes the 
revision that was
-                                       // just added in the working 
transaction.
-                                       $this->initEditCount();
-                               }
-                       }
-               }
-               // edit count in user cache too
-               $this->invalidateCache();
+                       // edit count in user cache too
+                       $that->invalidateCache();
+               } );
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I930222d5e831bb3729194abbdcb3cab194c70494
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to