Defer the watchlist update query in EditPage.
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 2 Oct 2012 22:29:05 +0000 (15:29 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 2 Oct 2012 22:30:24 +0000 (15:30 -0700)
Change-Id: I9441a2778065b03593a0e42154bb0a6e44f0a196

includes/EditPage.php

index c138824..3922719 100644 (file)
@@ -1458,7 +1458,7 @@ class EditPage {
 
                if ( $doEditStatus->isOK() ) {
                        $result['redirect'] = Title::newFromRedirect( $text ) !== null;
-                       $this->commitWatch();
+                       $this->updateWatchlist();
                        wfProfileOut( __METHOD__ );
                        return $status;
                } else {
@@ -1479,19 +1479,27 @@ class EditPage {
        }
 
        /**
-        * Commit the change of watch status
+        * Register the change of watch status
         */
-       protected function commitWatch() {
+       protected function updateWatchlist() {
                global $wgUser;
+
                if ( $wgUser->isLoggedIn() && $this->watchthis != $wgUser->isWatched( $this->mTitle ) ) {
+                       $fname = __METHOD__;
+                       $title = $this->mTitle;
+                       $watch = $this->watchthis;
+
+                       // Do this in its own transaction to reduce contention...
                        $dbw = wfGetDB( DB_MASTER );
-                       $dbw->begin( __METHOD__ );
-                       if ( $this->watchthis ) {
-                               WatchAction::doWatch( $this->mTitle, $wgUser );
-                       } else {
-                               WatchAction::doUnwatch( $this->mTitle, $wgUser );
-                       }
-                       $dbw->commit( __METHOD__ );
+                       $dbw->onTransactionIdle( function() use ( $dbw, $title, $watch, $wgUser, $fname ) {
+                               $dbw->begin( $fname );
+                               if ( $watch ) {
+                                       WatchAction::doWatch( $title, $wgUser );
+                               } else {
+                                       WatchAction::doUnwatch( $title, $wgUser );
+                               }
+                               $dbw->commit( $fname );
+                       } );
                }
        }