Merge "Fix Postgres support"
[lhc/web/wiklou.git] / includes / deferred / DeferredUpdates.php
index bbe8687..a3a37f6 100644 (file)
@@ -55,8 +55,6 @@ class DeferredUpdates {
        private static $preSendUpdates = [];
        /** @var DeferrableUpdate[] Updates to be deferred until after request end */
        private static $postSendUpdates = [];
-       /** @var bool Whether to just run updates in addUpdate() */
-       private static $immediateMode = false;
 
        const ALL = 0; // all updates; in web requests, use only after flushing the output buffer
        const PRESEND = 1; // for updates that should run before flushing output buffer
@@ -90,12 +88,6 @@ class DeferredUpdates {
                        self::push( self::$postSendUpdates, $update );
                }
 
-               if ( self::$immediateMode ) {
-                       // No more explicit doUpdates() calls will happen, so run this now
-                       self::doUpdates( 'run' );
-                       return;
-               }
-
                // Try to run the updates now if in CLI mode and no transaction is active.
                // This covers scripts that don't/barely use the DB but make updates to other stores.
                if ( $wgCommandLineMode ) {
@@ -140,9 +132,10 @@ class DeferredUpdates {
        /**
         * @param bool $value Whether to just immediately run updates in addUpdate()
         * @since 1.28
+        * @deprecated 1.29 Causes issues in Web-executed jobs - see T165714 and T100085.
         */
        public static function setImmediateMode( $value ) {
-               self::$immediateMode = (bool)$value;
+               wfDeprecated( __METHOD__, '1.29' );
        }
 
        /**
@@ -293,7 +286,7 @@ class DeferredUpdates {
                }
 
                // Avoiding running updates without them having outer scope
-               if ( !self::getBusyDbConnections() ) {
+               if ( !self::areDatabaseTransactionsActive() ) {
                        self::doUpdates( $mode );
                        return true;
                }
@@ -339,6 +332,7 @@ class DeferredUpdates {
 
        /**
         * @param integer $stage DeferredUpdates constant (PRESEND, POSTSEND, or ALL)
+        * @return DeferrableUpdate[]
         * @since 1.29
         */
        public static function getPendingUpdates( $stage = self::ALL ) {
@@ -362,16 +356,19 @@ class DeferredUpdates {
        }
 
        /**
-        * @return IDatabase[] Connection where commit() cannot be called yet
+        * @return bool If a transaction round is active or connection is not ready for commit()
         */
-       private static function getBusyDbConnections() {
-               $connsBusy = [];
-
+       private static function areDatabaseTransactionsActive() {
                $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+               if ( $lbFactory->hasTransactionRound() ) {
+                       return true;
+               }
+
+               $connsBusy = false;
                $lbFactory->forEachLB( function ( LoadBalancer $lb ) use ( &$connsBusy ) {
                        $lb->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( &$connsBusy ) {
                                if ( $conn->writesOrCallbacksPending() || $conn->explicitTrxActive() ) {
-                                       $connsBusy[] = $conn;
+                                       $connsBusy = true;
                                }
                        } );
                } );