From 43b44d84e5d597aed3d749293db891cf02974701 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 2 Oct 2012 15:29:05 -0700 Subject: [PATCH] Defer the watchlist update query in EditPage. Change-Id: I9441a2778065b03593a0e42154bb0a6e44f0a196 --- includes/EditPage.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) 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 ); + } ); } } -- 2.20.1