From: Aaron Schulz Date: Tue, 2 Oct 2012 22:29:05 +0000 (-0700) Subject: Defer the watchlist update query in EditPage. X-Git-Tag: 1.31.0-rc.0~22193^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dcompta/operations/supprimer.php?a=commitdiff_plain;h=43b44d84e5d597aed3d749293db891cf02974701;p=lhc%2Fweb%2Fwiklou.git Defer the watchlist update query in EditPage. Change-Id: I9441a2778065b03593a0e42154bb0a6e44f0a196 --- diff --git a/includes/EditPage.php b/includes/EditPage.php index c138824688..39227198c2 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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 ); + } ); } }