r77972 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77971‎ | r77972 | r77973 >
Date:11:49, 7 December 2010
Author:ialex
Status:ok (Comments)
Tags:
Comment:
Merged wfDoUpdates() and MediaWiki::doUpdates() in wfDoUpdates(); avoids code duplication
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -2859,14 +2859,34 @@
28602860
28612861 /**
28622862 * Do any deferred updates and clear the list
2863 - * TODO: This could be in Wiki.php if that class made any sense at all
 2863+ *
 2864+ * @param $commit Boolean: commit after every update to prevent lock contention
28642865 */
2865 -function wfDoUpdates() {
 2866+function wfDoUpdates( $commit = false ) {
28662867 global $wgDeferredUpdateList;
 2868+
 2869+ wfProfileIn( __METHOD__ );
 2870+
 2871+ // No need to get master connections in case of empty updates array
 2872+ if ( !count( $wgDeferredUpdateList ) ) {
 2873+ wfProfileOut( __METHOD__ );
 2874+ return;
 2875+ }
 2876+
 2877+ if ( $commit ) {
 2878+ $dbw = wfGetDB( DB_MASTER );
 2879+ }
 2880+
28672881 foreach ( $wgDeferredUpdateList as $update ) {
28682882 $update->doUpdate();
 2883+
 2884+ if ( $commit && $dbw->trxLevel() ) {
 2885+ $dbw->commit();
 2886+ }
28692887 }
 2888+
28702889 $wgDeferredUpdateList = array();
 2890+ wfProfileOut( __METHOD__ );
28712891 }
28722892
28732893 /**
Index: trunk/phase3/includes/Wiki.php
@@ -153,9 +153,8 @@
154154 // the Read array in order for the user to see it. (We have to check here to
155155 // catch special pages etc. We check again in Article::view())
156156 if( !is_null( $title ) && !$title->userCanRead() ) {
157 - global $wgDeferredUpdateList;
158157 $output->loginToUse();
159 - $this->finalCleanup( $wgDeferredUpdateList, $output );
 158+ $this->finalCleanup( $output );
160159 $output->disable();
161160 return false;
162161 }
@@ -361,10 +360,9 @@
362361 * Cleaning up request by doing:
363362 ** deferred updates, DB transaction, and the output
364363 *
365 - * @param $deferredUpdates array of updates to do
366364 * @param $output OutputPage
367365 */
368 - function finalCleanup( &$deferredUpdates, &$output ) {
 366+ function finalCleanup( &$output ) {
369367 wfProfileIn( __METHOD__ );
370368 // Now commit any transactions, so that unreported errors after
371369 // output() don't roll back the whole DB transaction
@@ -373,7 +371,7 @@
374372 // Output everything!
375373 $output->output();
376374 // Do any deferred jobs
377 - $this->doUpdates( $deferredUpdates );
 375+ wfDoUpdates( true );
378376 // Close the session so that jobs don't access the current session
379377 session_write_close();
380378 $this->doJobs();
@@ -381,34 +379,6 @@
382380 }
383381
384382 /**
385 - * Deferred updates aren't really deferred anymore. It's important to report
386 - * errors to the user, and that means doing this before OutputPage::output().
387 - * Note that for page saves, the client will wait until the script exits
388 - * anyway before following the redirect.
389 - *
390 - * @param $updates array of objects that hold an update to do
391 - */
392 - function doUpdates( &$updates ) {
393 - wfProfileIn( __METHOD__ );
394 - /* No need to get master connections in case of empty updates array */
395 - if (!$updates) {
396 - wfProfileOut( __METHOD__ );
397 - return;
398 - }
399 -
400 - $dbw = wfGetDB( DB_MASTER );
401 - foreach( $updates as $up ) {
402 - $up->doUpdate();
403 -
404 - // Commit after every update to prevent lock contention
405 - if( $dbw->trxLevel() ) {
406 - $dbw->commit();
407 - }
408 - }
409 - wfProfileOut( __METHOD__ );
410 - }
411 -
412 - /**
413383 * Do a job from the job queue
414384 */
415385 function doJobs() {
Index: trunk/phase3/index.php
@@ -111,7 +111,7 @@
112112 $mediaWiki->setVal( 'UsePathInfo', $wgUsePathInfo );
113113
114114 $mediaWiki->performRequestForTitle( $wgTitle, $wgArticle, $wgOut, $wgUser, $wgRequest );
115 -$mediaWiki->finalCleanup( $wgDeferredUpdateList, $wgOut );
 115+$mediaWiki->finalCleanup( $wgOut );
116116
117117 $mediaWiki->restInPeace();
118118

Follow-up revisions

RevisionCommit summaryAuthorDate
r77985Per Nikerabbit, follow-up to r77972: use a string instead of boolean for read...ialex15:47, 7 December 2010

Comments

#Comment by Nikerabbit (talk | contribs)   13:34, 7 December 2010

Oh noes more boolean parameters. How about at least calling it like wfDoUpdates( 'individual transactions' ); or some such ;)?

Status & tagging log