Make DeferredUpdates::doUpdates use DataUpdate::runUpdates
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 8 Oct 2015 06:46:18 +0000 (23:46 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 8 Oct 2015 07:21:47 +0000 (07:21 +0000)
All DataUpdate objects will be managed by runUpdates() while
the other DeferrableUpdate objects will still be run here.
This respects the transaction sematics of DataUpdate a bit more.

Change-Id: Ia0d2dd26a38b0e8911589407b533b58d04d2b084

includes/deferred/DeferredUpdates.php

index 7d02a7a..8b3582d 100644 (file)
@@ -44,7 +44,7 @@ interface DeferrableUpdate {
  * @since 1.19
  */
 class DeferredUpdates {
-       /** @var array Updates to be deferred until the end of the request */
+       /** @var DeferrableUpdate[] Updates to be deferred until the end of the request */
        private static $updates = array();
        /** @var bool Defer updates fully even in CLI mode */
        private static $forceDeferral = false;
@@ -102,9 +102,22 @@ class DeferredUpdates {
 
                while ( count( $updates ) ) {
                        self::clearPendingUpdates();
-
-                       /** @var DeferrableUpdate $update */
+                       /** @var DataUpdate[] $dataUpdates */
+                       $dataUpdates = array();
+                       /** @var DeferrableUpdate[] $otherUpdates */
+                       $otherUpdates = array();
                        foreach ( $updates as $update ) {
+                               if ( $update instanceof DataUpdate ) {
+                                       $dataUpdates[] = $update;
+                               } else {
+                                       $otherUpdates[] = $update;
+                               }
+                       }
+
+                       // Delegate DataUpdate execution to the DataUpdate class
+                       DataUpdate::runUpdates( $dataUpdates, 'run' );
+                       // Execute the non-DataUpdate tasks
+                       foreach ( $otherUpdates as $update ) {
                                try {
                                        $update->doUpdate();