From 30caa2a8b992a66f3ec0727198162ccd260f2298 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Tue, 7 Dec 2010 11:49:13 +0000 Subject: [PATCH] Merged wfDoUpdates() and MediaWiki::doUpdates() in wfDoUpdates(); avoids code duplication --- includes/GlobalFunctions.php | 24 ++++++++++++++++++++++-- includes/Wiki.php | 36 +++--------------------------------- index.php | 2 +- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 1d1a609507..e9c8b858e2 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2859,14 +2859,34 @@ function wfMakeUrlIndex( $url ) { /** * Do any deferred updates and clear the list - * TODO: This could be in Wiki.php if that class made any sense at all + * + * @param $commit Boolean: commit after every update to prevent lock contention */ -function wfDoUpdates() { +function wfDoUpdates( $commit = false ) { global $wgDeferredUpdateList; + + wfProfileIn( __METHOD__ ); + + // No need to get master connections in case of empty updates array + if ( !count( $wgDeferredUpdateList ) ) { + wfProfileOut( __METHOD__ ); + return; + } + + if ( $commit ) { + $dbw = wfGetDB( DB_MASTER ); + } + foreach ( $wgDeferredUpdateList as $update ) { $update->doUpdate(); + + if ( $commit && $dbw->trxLevel() ) { + $dbw->commit(); + } } + $wgDeferredUpdateList = array(); + wfProfileOut( __METHOD__ ); } /** diff --git a/includes/Wiki.php b/includes/Wiki.php index d8bd09cd22..7440423a24 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -153,9 +153,8 @@ class MediaWiki { // the Read array in order for the user to see it. (We have to check here to // catch special pages etc. We check again in Article::view()) if( !is_null( $title ) && !$title->userCanRead() ) { - global $wgDeferredUpdateList; $output->loginToUse(); - $this->finalCleanup( $wgDeferredUpdateList, $output ); + $this->finalCleanup( $output ); $output->disable(); return false; } @@ -361,10 +360,9 @@ class MediaWiki { * Cleaning up request by doing: ** deferred updates, DB transaction, and the output * - * @param $deferredUpdates array of updates to do * @param $output OutputPage */ - function finalCleanup( &$deferredUpdates, &$output ) { + function finalCleanup( &$output ) { wfProfileIn( __METHOD__ ); // Now commit any transactions, so that unreported errors after // output() don't roll back the whole DB transaction @@ -373,41 +371,13 @@ class MediaWiki { // Output everything! $output->output(); // Do any deferred jobs - $this->doUpdates( $deferredUpdates ); + wfDoUpdates( true ); // Close the session so that jobs don't access the current session session_write_close(); $this->doJobs(); wfProfileOut( __METHOD__ ); } - /** - * Deferred updates aren't really deferred anymore. It's important to report - * errors to the user, and that means doing this before OutputPage::output(). - * Note that for page saves, the client will wait until the script exits - * anyway before following the redirect. - * - * @param $updates array of objects that hold an update to do - */ - function doUpdates( &$updates ) { - wfProfileIn( __METHOD__ ); - /* No need to get master connections in case of empty updates array */ - if (!$updates) { - wfProfileOut( __METHOD__ ); - return; - } - - $dbw = wfGetDB( DB_MASTER ); - foreach( $updates as $up ) { - $up->doUpdate(); - - // Commit after every update to prevent lock contention - if( $dbw->trxLevel() ) { - $dbw->commit(); - } - } - wfProfileOut( __METHOD__ ); - } - /** * Do a job from the job queue */ diff --git a/index.php b/index.php index b0454ddbfa..020e94d9dc 100644 --- a/index.php +++ b/index.php @@ -111,7 +111,7 @@ $mediaWiki->setVal( 'UseExternalEditor', $wgUseExternalEditor ); $mediaWiki->setVal( 'UsePathInfo', $wgUsePathInfo ); $mediaWiki->performRequestForTitle( $wgTitle, $wgArticle, $wgOut, $wgUser, $wgRequest ); -$mediaWiki->finalCleanup( $wgDeferredUpdateList, $wgOut ); +$mediaWiki->finalCleanup( $wgOut ); $mediaWiki->restInPeace(); -- 2.20.1