jenkins-bot has submitted this change and it was merged.

Change subject: Remove wfGetCaller() dependency from DatabaseBase
......................................................................


Remove wfGetCaller() dependency from DatabaseBase

Change-Id: I3e240b2eb5c1f6a21f1bc974c3d28f5755c7451a
---
M includes/auth/EmailNotificationSecondaryAuthenticationProvider.php
M includes/auth/TemporaryPasswordPrimaryAuthenticationProvider.php
M includes/changes/RecentChange.php
M includes/db/Database.php
M includes/deferred/AtomicSectionUpdate.php
M includes/deferred/AutoCommitUpdate.php
M includes/deferred/LinksUpdate.php
M includes/deferred/MWCallableUpdate.php
M includes/filerepo/LocalRepo.php
M includes/filerepo/file/LocalFile.php
M includes/jobqueue/JobQueueDB.php
M includes/jobqueue/jobs/RecentChangesUpdateJob.php
M includes/jobqueue/utils/PurgeJobUtils.php
M includes/libs/rdbms/database/DBConnRef.php
M includes/libs/rdbms/database/IDatabase.php
M includes/page/WikiPage.php
M includes/resourceloader/ResourceLoaderModule.php
M includes/revisiondelete/RevDelList.php
M includes/user/User.php
M includes/user/UserRightsProxy.php
M tests/phpunit/includes/db/DatabaseTest.php
21 files changed, 301 insertions(+), 232 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/auth/EmailNotificationSecondaryAuthenticationProvider.php 
b/includes/auth/EmailNotificationSecondaryAuthenticationProvider.php
index a82f018..a485531 100644
--- a/includes/auth/EmailNotificationSecondaryAuthenticationProvider.php
+++ b/includes/auth/EmailNotificationSecondaryAuthenticationProvider.php
@@ -51,15 +51,18 @@
                        && !$this->manager->getAuthenticationSessionData( 
'no-email' )
                ) {
                        // TODO show 
'confirmemail_oncreate'/'confirmemail_sendfailed' message
-                       wfGetDB( DB_MASTER )->onTransactionIdle( function () 
use ( $user ) {
-                               $user = $user->getInstanceForUpdate();
-                               $status = $user->sendConfirmationMail();
-                               $user->saveSettings();
-                               if ( !$status->isGood() ) {
-                                       $this->logger->warning( 'Could not send 
confirmation email: ' .
-                                               $status->getWikiText( false, 
false, 'en' ) );
-                               }
-                       } );
+                       wfGetDB( DB_MASTER )->onTransactionIdle(
+                               function () use ( $user ) {
+                                       $user = $user->getInstanceForUpdate();
+                                       $status = $user->sendConfirmationMail();
+                                       $user->saveSettings();
+                                       if ( !$status->isGood() ) {
+                                               $this->logger->warning( 'Could 
not send confirmation email: ' .
+                                                       $status->getWikiText( 
false, false, 'en' ) );
+                                       }
+                               },
+                               __METHOD__
+                       );
                }
 
                return AuthenticationResponse::newPass();
diff --git a/includes/auth/TemporaryPasswordPrimaryAuthenticationProvider.php 
b/includes/auth/TemporaryPasswordPrimaryAuthenticationProvider.php
index f5571c7..f16423d 100644
--- a/includes/auth/TemporaryPasswordPrimaryAuthenticationProvider.php
+++ b/includes/auth/TemporaryPasswordPrimaryAuthenticationProvider.php
@@ -304,10 +304,13 @@
 
                if ( $sendMail ) {
                        // Send email after DB commit
-                       $dbw->onTransactionIdle( function () use ( $req ) {
-                               /** @var TemporaryPasswordAuthenticationRequest 
$req */
-                               $this->sendPasswordResetEmail( $req );
-                       } );
+                       $dbw->onTransactionIdle(
+                               function () use ( $req ) {
+                                       /** @var 
TemporaryPasswordAuthenticationRequest $req */
+                                       $this->sendPasswordResetEmail( $req );
+                               },
+                               __METHOD__
+                       );
                }
        }
 
@@ -375,9 +378,12 @@
 
                if ( $mailpassword ) {
                        // Send email after DB commit
-                       wfGetDB( DB_MASTER )->onTransactionIdle( function () 
use ( $user, $creator, $req ) {
-                               $this->sendNewAccountEmail( $user, $creator, 
$req->password );
-                       } );
+                       wfGetDB( DB_MASTER )->onTransactionIdle(
+                               function () use ( $user, $creator, $req ) {
+                                       $this->sendNewAccountEmail( $user, 
$creator, $req->password );
+                               },
+                               __METHOD__
+                       );
                }
 
                return $mailpassword ? 'byemail' : null;
diff --git a/includes/changes/RecentChange.php 
b/includes/changes/RecentChange.php
index 8e74674..590fd37 100644
--- a/includes/changes/RecentChange.php
+++ b/includes/changes/RecentChange.php
@@ -342,18 +342,21 @@
                        ) {
                                // @FIXME: This would be better as an extension 
hook
                                // Send emails or email jobs once this row is 
safely committed
-                               $dbw->onTransactionIdle( function () use ( 
$editor, $title ) {
-                                       $enotif = new EmailNotification();
-                                       $enotif->notifyOnPageChange(
-                                               $editor,
-                                               $title,
-                                               $this->mAttribs['rc_timestamp'],
-                                               $this->mAttribs['rc_comment'],
-                                               $this->mAttribs['rc_minor'],
-                                               
$this->mAttribs['rc_last_oldid'],
-                                               $this->mExtra['pageStatus']
-                                       );
-                               } );
+                               $dbw->onTransactionIdle(
+                                       function () use ( $editor, $title ) {
+                                               $enotif = new 
EmailNotification();
+                                               $enotif->notifyOnPageChange(
+                                                       $editor,
+                                                       $title,
+                                                       
$this->mAttribs['rc_timestamp'],
+                                                       
$this->mAttribs['rc_comment'],
+                                                       
$this->mAttribs['rc_minor'],
+                                                       
$this->mAttribs['rc_last_oldid'],
+                                                       
$this->mExtra['pageStatus']
+                                               );
+                                       },
+                                       __METHOD__
+                               );
                        }
                }
 
diff --git a/includes/db/Database.php b/includes/db/Database.php
index 3fa1335..6cfff0e 100644
--- a/includes/db/Database.php
+++ b/includes/db/Database.php
@@ -85,7 +85,7 @@
        protected $mTrxPreCommitCallbacks = [];
        /** @var array[] List of (callable, method name) */
        protected $mTrxEndCallbacks = [];
-       /** @var array[] Map of (name => (callable, method name)) */
+       /** @var callable[] Map of (name => callable) */
        protected $mTrxRecurringCallbacks = [];
        /** @var bool Whether to suppress triggering of transaction end 
callbacks */
        protected $mTrxEndCallbacksSuppressed = false;
@@ -2671,23 +2671,23 @@
                return false;
        }
 
-       final public function onTransactionResolution( callable $callback ) {
+       final public function onTransactionResolution( callable $callback, 
$fname = __METHOD__ ) {
                if ( !$this->mTrxLevel ) {
                        throw new DBUnexpectedError( $this, "No transaction is 
active." );
                }
-               $this->mTrxEndCallbacks[] = [ $callback, wfGetCaller() ];
+               $this->mTrxEndCallbacks[] = [ $callback, $fname ];
        }
 
-       final public function onTransactionIdle( callable $callback ) {
-               $this->mTrxIdleCallbacks[] = [ $callback, wfGetCaller() ];
+       final public function onTransactionIdle( callable $callback, $fname = 
__METHOD__ ) {
+               $this->mTrxIdleCallbacks[] = [ $callback, $fname ];
                if ( !$this->mTrxLevel ) {
                        $this->runOnTransactionIdleCallbacks( 
self::TRIGGER_IDLE );
                }
        }
 
-       final public function onTransactionPreCommitOrIdle( callable $callback 
) {
+       final public function onTransactionPreCommitOrIdle( callable $callback, 
$fname = __METHOD__ ) {
                if ( $this->mTrxLevel ) {
-                       $this->mTrxPreCommitCallbacks[] = [ $callback, 
wfGetCaller() ];
+                       $this->mTrxPreCommitCallbacks[] = [ $callback, $fname ];
                } else {
                        // If no transaction is active, then make one for this 
callback
                        $this->startAtomic( __METHOD__ );
@@ -2703,7 +2703,7 @@
 
        final public function setTransactionListener( $name, callable $callback 
= null ) {
                if ( $callback ) {
-                       $this->mTrxRecurringCallbacks[$name] = [ $callback, 
wfGetCaller() ];
+                       $this->mTrxRecurringCallbacks[$name] = $callback;
                } else {
                        unset( $this->mTrxRecurringCallbacks[$name] );
                }
@@ -2818,9 +2818,8 @@
                /** @var Exception $e */
                $e = null; // first exception
 
-               foreach ( $this->mTrxRecurringCallbacks as $callback ) {
+               foreach ( $this->mTrxRecurringCallbacks as $phpCallback ) {
                        try {
-                               list( $phpCallback ) = $callback;
                                $phpCallback( $trigger, $this );
                        } catch ( Exception $ex ) {
                                call_user_func( $this->errorLogger, $ex );
@@ -3527,15 +3526,18 @@
                                // There is a good chance an exception was 
thrown, causing any early return
                                // from the caller. Let any error handler get a 
chance to issue rollback().
                                // If there isn't one, let the error bubble up 
and trigger server-side rollback.
-                               $this->onTransactionResolution( function () use 
( $lockKey, $fname ) {
-                                       $this->unlock( $lockKey, $fname );
-                               } );
+                               $this->onTransactionResolution(
+                                       function () use ( $lockKey, $fname ) {
+                                               $this->unlock( $lockKey, $fname 
);
+                                       },
+                                       $fname
+                               );
                        } else {
                                $this->unlock( $lockKey, $fname );
                        }
                } );
 
-               $this->commit( __METHOD__, self::FLUSHING_INTERNAL );
+               $this->commit( $fname, self::FLUSHING_INTERNAL );
 
                return $unlocker;
        }
diff --git a/includes/deferred/AtomicSectionUpdate.php 
b/includes/deferred/AtomicSectionUpdate.php
index a348719..6585575 100644
--- a/includes/deferred/AtomicSectionUpdate.php
+++ b/includes/deferred/AtomicSectionUpdate.php
@@ -24,7 +24,7 @@
                $this->callback = $callback;
 
                if ( $this->dbw->trxLevel() ) {
-                       $this->dbw->onTransactionResolution( [ $this, 
'cancelOnRollback' ] );
+                       $this->dbw->onTransactionResolution( [ $this, 
'cancelOnRollback' ], $fname );
                }
        }
 
diff --git a/includes/deferred/AutoCommitUpdate.php 
b/includes/deferred/AutoCommitUpdate.php
index d26cf9d..d61dec2 100644
--- a/includes/deferred/AutoCommitUpdate.php
+++ b/includes/deferred/AutoCommitUpdate.php
@@ -23,7 +23,7 @@
                $this->callback = $callback;
 
                if ( $this->dbw->trxLevel() ) {
-                       $this->dbw->onTransactionResolution( [ $this, 
'cancelOnRollback' ] );
+                       $this->dbw->onTransactionResolution( [ $this, 
'cancelOnRollback' ], $fname );
                }
        }
 
diff --git a/includes/deferred/LinksUpdate.php 
b/includes/deferred/LinksUpdate.php
index e24a9c0..d18349b 100644
--- a/includes/deferred/LinksUpdate.php
+++ b/includes/deferred/LinksUpdate.php
@@ -174,9 +174,12 @@
                // Commit and release the lock (if set)
                ScopedCallback::consume( $scopedLock );
                // Run post-commit hooks without DBO_TRX
-               $this->getDB()->onTransactionIdle( function() {
-                       Hooks::run( 'LinksUpdateComplete', [ &$this ] );
-               } );
+               $this->getDB()->onTransactionIdle(
+                       function () {
+                               Hooks::run( 'LinksUpdateComplete', [ &$this ] );
+                       },
+                       __METHOD__
+               );
        }
 
        /**
diff --git a/includes/deferred/MWCallableUpdate.php 
b/includes/deferred/MWCallableUpdate.php
index 47b162c..5247e97 100644
--- a/includes/deferred/MWCallableUpdate.php
+++ b/includes/deferred/MWCallableUpdate.php
@@ -19,7 +19,7 @@
                $this->fname = $fname;
 
                if ( $dbw && $dbw->trxLevel() ) {
-                       $dbw->onTransactionResolution( [ $this, 
'cancelOnRollback' ] );
+                       $dbw->onTransactionResolution( [ $this, 
'cancelOnRollback' ], $fname );
                }
        }
 
diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php
index fccb755..7b40a7b 100644
--- a/includes/filerepo/LocalRepo.php
+++ b/includes/filerepo/LocalRepo.php
@@ -500,9 +500,12 @@
        function invalidateImageRedirect( Title $title ) {
                $key = $this->getSharedCacheKey( 'image_redirect', md5( 
$title->getDBkey() ) );
                if ( $key ) {
-                       $this->getMasterDB()->onTransactionPreCommitOrIdle( 
function() use ( $key ) {
-                               ObjectCache::getMainWANInstance()->delete( $key 
);
-                       } );
+                       $this->getMasterDB()->onTransactionPreCommitOrIdle(
+                               function () use ( $key ) {
+                                       
ObjectCache::getMainWANInstance()->delete( $key );
+                               },
+                               __METHOD__
+                       );
                }
        }
 
diff --git a/includes/filerepo/file/LocalFile.php 
b/includes/filerepo/file/LocalFile.php
index d63a91b..618272c 100644
--- a/includes/filerepo/file/LocalFile.php
+++ b/includes/filerepo/file/LocalFile.php
@@ -313,9 +313,12 @@
                        return;
                }
 
-               $this->repo->getMasterDB()->onTransactionPreCommitOrIdle( 
function() use ( $key ) {
-                       ObjectCache::getMainWANInstance()->delete( $key );
-               } );
+               $this->repo->getMasterDB()->onTransactionPreCommitOrIdle(
+                       function () use ( $key ) {
+                               ObjectCache::getMainWANInstance()->delete( $key 
);
+                       },
+                       __METHOD__
+               );
        }
 
        /**
@@ -2002,12 +2005,15 @@
                        }
                        // Release the lock *after* commit to avoid row-level 
contention.
                        // Make sure it triggers on rollback() as well as 
commit() (T132921).
-                       $dbw->onTransactionResolution( function () use ( 
$logger ) {
-                               $status = $this->releaseFileLock();
-                               if ( !$status->isGood() ) {
-                                       $logger->error( "Failed to unlock 
'{file}'", [ 'file' => $this->name ] );
-                               }
-                       } );
+                       $dbw->onTransactionResolution(
+                               function () use ( $logger ) {
+                                       $status = $this->releaseFileLock();
+                                       if ( !$status->isGood() ) {
+                                               $logger->error( "Failed to 
unlock '{file}'", [ 'file' => $this->name ] );
+                                       }
+                               },
+                               __METHOD__
+                       );
                        // Callers might care if the SELECT snapshot is safely 
fresh
                        $this->lockedOwnTrx = $makesTransaction;
                }
diff --git a/includes/jobqueue/JobQueueDB.php b/includes/jobqueue/JobQueueDB.php
index 50727a2..856cdfd 100644
--- a/includes/jobqueue/JobQueueDB.php
+++ b/includes/jobqueue/JobQueueDB.php
@@ -186,7 +186,8 @@
                $dbw->onTransactionIdle(
                        function () use ( $dbw, $jobs, $flags, $method ) {
                                $this->doBatchPushInternal( $dbw, $jobs, 
$flags, $method );
-                       }
+                       },
+                       __METHOD__
                );
        }
 
@@ -494,15 +495,18 @@
                // jobs to become no-ops without any actual jobs that made them 
redundant.
                $dbw = $this->getMasterDB();
                $cache = $this->dupCache;
-               $dbw->onTransactionIdle( function () use ( $cache, $params, 
$key, $dbw ) {
-                       $timestamp = $cache->get( $key ); // current last 
timestamp of this job
-                       if ( $timestamp && $timestamp >= 
$params['rootJobTimestamp'] ) {
-                               return true; // a newer version of this root 
job was enqueued
-                       }
+               $dbw->onTransactionIdle(
+                       function () use ( $cache, $params, $key, $dbw ) {
+                               $timestamp = $cache->get( $key ); // current 
last timestamp of this job
+                               if ( $timestamp && $timestamp >= 
$params['rootJobTimestamp'] ) {
+                                       return true; // a newer version of this 
root job was enqueued
+                               }
 
-                       // Update the timestamp of the last root job started at 
the location...
-                       return $cache->set( $key, $params['rootJobTimestamp'], 
JobQueueDB::ROOTJOB_TTL );
-               } );
+                               // Update the timestamp of the last root job 
started at the location...
+                               return $cache->set( $key, 
$params['rootJobTimestamp'], JobQueueDB::ROOTJOB_TTL );
+                       },
+                       __METHOD__
+               );
 
                return true;
        }
diff --git a/includes/jobqueue/jobs/RecentChangesUpdateJob.php 
b/includes/jobqueue/jobs/RecentChangesUpdateJob.php
index 809fb63..0e90674 100644
--- a/includes/jobqueue/jobs/RecentChangesUpdateJob.php
+++ b/includes/jobqueue/jobs/RecentChangesUpdateJob.php
@@ -19,6 +19,7 @@
  * @author Aaron Schulz
  * @ingroup JobQueue
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Job for pruning recent changes
@@ -81,7 +82,7 @@
                        return; // already in progress
                }
 
-               $factory = wfGetLBFactory();
+               $factory = 
MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
                $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
                $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
                do {
@@ -119,109 +120,112 @@
                $dbw = wfGetDB( DB_MASTER );
                // JobRunner uses DBO_TRX, but doesn't call begin/commit itself;
                // onTransactionIdle() will run immediately since there is no 
trx.
-               $dbw->onTransactionIdle( function() use ( $dbw, $days, $window 
) {
-                       $factory = wfGetLBFactory();
-                       $ticket = $factory->getEmptyTransactionTicket( 
__METHOD__ );
-                       // Avoid disconnect/ping() cycle that makes locks fall 
off
-                       $dbw->setSessionOptions( [ 'connTimeout' => 900 ] );
+               $dbw->onTransactionIdle(
+                       function () use ( $dbw, $days, $window ) {
+                               $factory = 
MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+                               $ticket = $factory->getEmptyTransactionTicket( 
__METHOD__ );
+                               // Avoid disconnect/ping() cycle that makes 
locks fall off
+                               $dbw->setSessionOptions( [ 'connTimeout' => 900 
] );
 
-                       $lockKey = wfWikiID() . '-activeusers';
-                       if ( !$dbw->lock( $lockKey, __METHOD__, 1 ) ) {
-                               return; // exclusive update (avoids duplicate 
entries)
-                       }
+                               $lockKey = wfWikiID() . '-activeusers';
+                               if ( !$dbw->lock( $lockKey, __METHOD__, 1 ) ) {
+                                       return; // exclusive update (avoids 
duplicate entries)
+                               }
 
-                       $nowUnix = time();
-                       // Get the last-updated timestamp for the cache
-                       $cTime = $dbw->selectField( 'querycache_info',
-                               'qci_timestamp',
-                               [ 'qci_type' => 'activeusers' ]
-                       );
-                       $cTimeUnix = $cTime ? wfTimestamp( TS_UNIX, $cTime ) : 
1;
+                               $nowUnix = time();
+                               // Get the last-updated timestamp for the cache
+                               $cTime = $dbw->selectField( 'querycache_info',
+                                       'qci_timestamp',
+                                       [ 'qci_type' => 'activeusers' ]
+                               );
+                               $cTimeUnix = $cTime ? wfTimestamp( TS_UNIX, 
$cTime ) : 1;
 
-                       // Pick the date range to fetch from. This is normally 
from the last
-                       // update to till the present time, but has a limited 
window for sanity.
-                       // If the window is limited, multiple runs are need to 
fully populate it.
-                       $sTimestamp = max( $cTimeUnix, $nowUnix - $days * 86400 
);
-                       $eTimestamp = min( $sTimestamp + $window, $nowUnix );
+                               // Pick the date range to fetch from. This is 
normally from the last
+                               // update to till the present time, but has a 
limited window for sanity.
+                               // If the window is limited, multiple runs are 
need to fully populate it.
+                               $sTimestamp = max( $cTimeUnix, $nowUnix - $days 
* 86400 );
+                               $eTimestamp = min( $sTimestamp + $window, 
$nowUnix );
 
-                       // Get all the users active since the last update
-                       $res = $dbw->select(
-                               [ 'recentchanges' ],
-                               [ 'rc_user_text', 'lastedittime' => 
'MAX(rc_timestamp)' ],
-                               [
-                                       'rc_user > 0', // actual accounts
-                                       'rc_type != ' . $dbw->addQuotes( 
RC_EXTERNAL ), // no wikidata
-                                       'rc_log_type IS NULL OR rc_log_type != 
' . $dbw->addQuotes( 'newusers' ),
-                                       'rc_timestamp >= ' . $dbw->addQuotes( 
$dbw->timestamp( $sTimestamp ) ),
-                                       'rc_timestamp <= ' . $dbw->addQuotes( 
$dbw->timestamp( $eTimestamp ) )
-                               ],
-                               __METHOD__,
-                               [
-                                       'GROUP BY' => [ 'rc_user_text' ],
-                                       'ORDER BY' => 'NULL' // avoid filesort
-                               ]
-                       );
-                       $names = [];
-                       foreach ( $res as $row ) {
-                               $names[$row->rc_user_text] = $row->lastedittime;
-                       }
+                               // Get all the users active since the last 
update
+                               $res = $dbw->select(
+                                       [ 'recentchanges' ],
+                                       [ 'rc_user_text', 'lastedittime' => 
'MAX(rc_timestamp)' ],
+                                       [
+                                               'rc_user > 0', // actual 
accounts
+                                               'rc_type != ' . 
$dbw->addQuotes( RC_EXTERNAL ), // no wikidata
+                                               'rc_log_type IS NULL OR 
rc_log_type != ' . $dbw->addQuotes( 'newusers' ),
+                                               'rc_timestamp >= ' . 
$dbw->addQuotes( $dbw->timestamp( $sTimestamp ) ),
+                                               'rc_timestamp <= ' . 
$dbw->addQuotes( $dbw->timestamp( $eTimestamp ) )
+                                       ],
+                                       __METHOD__,
+                                       [
+                                               'GROUP BY' => [ 'rc_user_text' 
],
+                                               'ORDER BY' => 'NULL' // avoid 
filesort
+                                       ]
+                               );
+                               $names = [];
+                               foreach ( $res as $row ) {
+                                       $names[$row->rc_user_text] = 
$row->lastedittime;
+                               }
 
-                       // Rotate out users that have not edited in too long 
(according to old data set)
-                       $dbw->delete( 'querycachetwo',
-                               [
-                                       'qcc_type' => 'activeusers',
-                                       'qcc_value < ' . $dbw->addQuotes( 
$nowUnix - $days * 86400 ) // TS_UNIX
-                               ],
-                               __METHOD__
-                       );
-
-                       // Find which of the recently active users are already 
accounted for
-                       if ( count( $names ) ) {
-                               $res = $dbw->select( 'querycachetwo',
-                                       [ 'user_name' => 'qcc_title' ],
+                               // Rotate out users that have not edited in too 
long (according to old data set)
+                               $dbw->delete( 'querycachetwo',
                                        [
                                                'qcc_type' => 'activeusers',
-                                               'qcc_namespace' => NS_USER,
-                                               'qcc_title' => array_keys( 
$names ) ],
+                                               'qcc_value < ' . 
$dbw->addQuotes( $nowUnix - $days * 86400 ) // TS_UNIX
+                                       ],
                                        __METHOD__
                                );
-                               foreach ( $res as $row ) {
-                                       unset( $names[$row->user_name] );
+
+                               // Find which of the recently active users are 
already accounted for
+                               if ( count( $names ) ) {
+                                       $res = $dbw->select( 'querycachetwo',
+                                               [ 'user_name' => 'qcc_title' ],
+                                               [
+                                                       'qcc_type' => 
'activeusers',
+                                                       'qcc_namespace' => 
NS_USER,
+                                                       'qcc_title' => 
array_keys( $names ) ],
+                                               __METHOD__
+                                       );
+                                       foreach ( $res as $row ) {
+                                               unset( $names[$row->user_name] 
);
+                                       }
                                }
-                       }
 
-                       // Insert the users that need to be added to the list
-                       if ( count( $names ) ) {
-                               $newRows = [];
-                               foreach ( $names as $name => $lastEditTime ) {
-                                       $newRows[] = [
-                                               'qcc_type' => 'activeusers',
-                                               'qcc_namespace' => NS_USER,
-                                               'qcc_title' => $name,
-                                               'qcc_value' => wfTimestamp( 
TS_UNIX, $lastEditTime ),
-                                               'qcc_namespacetwo' => 0, // 
unused
-                                               'qcc_titletwo' => '' // unused
-                                       ];
+                               // Insert the users that need to be added to 
the list
+                               if ( count( $names ) ) {
+                                       $newRows = [];
+                                       foreach ( $names as $name => 
$lastEditTime ) {
+                                               $newRows[] = [
+                                                       'qcc_type' => 
'activeusers',
+                                                       'qcc_namespace' => 
NS_USER,
+                                                       'qcc_title' => $name,
+                                                       'qcc_value' => 
wfTimestamp( TS_UNIX, $lastEditTime ),
+                                                       'qcc_namespacetwo' => 
0, // unused
+                                                       'qcc_titletwo' => '' // 
unused
+                                               ];
+                                       }
+                                       foreach ( array_chunk( $newRows, 500 ) 
as $rowBatch ) {
+                                               $dbw->insert( 'querycachetwo', 
$rowBatch, __METHOD__ );
+                                               
$factory->commitAndWaitForReplication( __METHOD__, $ticket );
+                                       }
                                }
-                               foreach ( array_chunk( $newRows, 500 ) as 
$rowBatch ) {
-                                       $dbw->insert( 'querycachetwo', 
$rowBatch, __METHOD__ );
-                                       $factory->commitAndWaitForReplication( 
__METHOD__, $ticket );
-                               }
-                       }
 
-                       // If a transaction was already started, it might have 
an old
-                       // snapshot, so kludge the timestamp range back as 
needed.
-                       $asOfTimestamp = min( $eTimestamp, 
(int)$dbw->trxTimestamp() );
+                               // If a transaction was already started, it 
might have an old
+                               // snapshot, so kludge the timestamp range back 
as needed.
+                               $asOfTimestamp = min( $eTimestamp, 
(int)$dbw->trxTimestamp() );
 
-                       // Touch the data freshness timestamp
-                       $dbw->replace( 'querycache_info',
-                               [ 'qci_type' ],
-                               [ 'qci_type' => 'activeusers',
-                                       'qci_timestamp' => $dbw->timestamp( 
$asOfTimestamp ) ], // not always $now
-                               __METHOD__
-                       );
+                               // Touch the data freshness timestamp
+                               $dbw->replace( 'querycache_info',
+                                       [ 'qci_type' ],
+                                       [ 'qci_type' => 'activeusers',
+                                               'qci_timestamp' => 
$dbw->timestamp( $asOfTimestamp ) ], // not always $now
+                                       __METHOD__
+                               );
 
-                       $dbw->unlock( $lockKey, __METHOD__ );
-               } );
+                               $dbw->unlock( $lockKey, __METHOD__ );
+                       },
+                       __METHOD__
+               );
        }
 }
diff --git a/includes/jobqueue/utils/PurgeJobUtils.php 
b/includes/jobqueue/utils/PurgeJobUtils.php
index 5eafcb3..d76d866 100644
--- a/includes/jobqueue/utils/PurgeJobUtils.php
+++ b/includes/jobqueue/utils/PurgeJobUtils.php
@@ -36,42 +36,45 @@
                        return;
                }
 
-               $dbw->onTransactionIdle( function() use ( $dbw, $namespace, 
$dbkeys ) {
-                       $services = MediaWikiServices::getInstance();
-                       $lbFactory = $services->getDBLoadBalancerFactory();
-                       // Determine which pages need to be updated.
-                       // This is necessary to prevent the job queue from 
smashing the DB with
-                       // large numbers of concurrent invalidations of the 
same page.
-                       $now = $dbw->timestamp();
-                       $ids = $dbw->selectFieldValues(
-                               'page',
-                               'page_id',
-                               [
-                                       'page_namespace' => $namespace,
-                                       'page_title' => $dbkeys,
-                                       'page_touched < ' . $dbw->addQuotes( 
$now )
-                               ],
-                               __METHOD__
-                       );
-
-                       if ( !$ids ) {
-                               return;
-                       }
-
-                       $batchSize = $services->getMainConfig()->get( 
'UpdateRowsPerQuery' );
-                       $ticket = $lbFactory->getEmptyTransactionTicket( 
__METHOD__ );
-                       foreach ( array_chunk( $ids, $batchSize ) as $idBatch ) 
{
-                               $dbw->update(
+               $dbw->onTransactionIdle(
+                       function () use ( $dbw, $namespace, $dbkeys ) {
+                               $services = MediaWikiServices::getInstance();
+                               $lbFactory = 
$services->getDBLoadBalancerFactory();
+                               // Determine which pages need to be updated.
+                               // This is necessary to prevent the job queue 
from smashing the DB with
+                               // large numbers of concurrent invalidations of 
the same page.
+                               $now = $dbw->timestamp();
+                               $ids = $dbw->selectFieldValues(
                                        'page',
-                                       [ 'page_touched' => $now ],
+                                       'page_id',
                                        [
-                                               'page_id' => $idBatch,
-                                               'page_touched < ' . 
$dbw->addQuotes( $now ) // handle races
+                                               'page_namespace' => $namespace,
+                                               'page_title' => $dbkeys,
+                                               'page_touched < ' . 
$dbw->addQuotes( $now )
                                        ],
                                        __METHOD__
                                );
-                               $lbFactory->commitAndWaitForReplication( 
__METHOD__, $ticket );
-                       }
-               } );
+
+                               if ( !$ids ) {
+                                       return;
+                               }
+
+                               $batchSize = $services->getMainConfig()->get( 
'UpdateRowsPerQuery' );
+                               $ticket = 
$lbFactory->getEmptyTransactionTicket( __METHOD__ );
+                               foreach ( array_chunk( $ids, $batchSize ) as 
$idBatch ) {
+                                       $dbw->update(
+                                               'page',
+                                               [ 'page_touched' => $now ],
+                                               [
+                                                       'page_id' => $idBatch,
+                                                       'page_touched < ' . 
$dbw->addQuotes( $now ) // handle races
+                                               ],
+                                               __METHOD__
+                                       );
+                                       
$lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
+                               }
+                       },
+                       __METHOD__
+               );
        }
 }
diff --git a/includes/libs/rdbms/database/DBConnRef.php 
b/includes/libs/rdbms/database/DBConnRef.php
index 3a18fc0..f940580 100644
--- a/includes/libs/rdbms/database/DBConnRef.php
+++ b/includes/libs/rdbms/database/DBConnRef.php
@@ -444,15 +444,15 @@
                return $this->__call( __FUNCTION__, func_get_args() );
        }
 
-       public function onTransactionResolution( callable $callback ) {
+       public function onTransactionResolution( callable $callback, $fname = 
__METHOD__ ) {
                return $this->__call( __FUNCTION__, func_get_args() );
        }
 
-       public function onTransactionIdle( callable $callback ) {
+       public function onTransactionIdle( callable $callback, $fname = 
__METHOD__ ) {
                return $this->__call( __FUNCTION__, func_get_args() );
        }
 
-       public function onTransactionPreCommitOrIdle( callable $callback ) {
+       public function onTransactionPreCommitOrIdle( callable $callback, 
$fname = __METHOD__ ) {
                return $this->__call( __FUNCTION__, func_get_args() );
        }
 
diff --git a/includes/libs/rdbms/database/IDatabase.php 
b/includes/libs/rdbms/database/IDatabase.php
index 026cbc5..9a0ffd5 100644
--- a/includes/libs/rdbms/database/IDatabase.php
+++ b/includes/libs/rdbms/database/IDatabase.php
@@ -1284,10 +1284,11 @@
         *   - How the transaction ended (IDatabase::TRIGGER_COMMIT or 
IDatabase::TRIGGER_ROLLBACK)
         *
         * @param callable $callback
+        * @param string $fname Caller name
         * @return mixed
         * @since 1.28
         */
-       public function onTransactionResolution( callable $callback );
+       public function onTransactionResolution( callable $callback, $fname = 
__METHOD__ );
 
        /**
         * Run a callback as soon as there is no transaction pending.
@@ -1306,9 +1307,10 @@
         *   - How the transaction ended (IDatabase::TRIGGER_COMMIT or 
IDatabase::TRIGGER_IDLE)
         *
         * @param callable $callback
+        * @param string $fname Caller name
         * @since 1.20
         */
-       public function onTransactionIdle( callable $callback );
+       public function onTransactionIdle( callable $callback, $fname = 
__METHOD__ );
 
        /**
         * Run a callback before the current transaction commits or now if 
there is none.
@@ -1322,9 +1324,10 @@
         * Updates will execute in the order they were enqueued.
         *
         * @param callable $callback
+        * @param string $fname Caller name
         * @since 1.22
         */
-       public function onTransactionPreCommitOrIdle( callable $callback );
+       public function onTransactionPreCommitOrIdle( callable $callback, 
$fname = __METHOD__ );
 
        /**
         * Run a callback each time any transaction commits or rolls back
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index 6c0c4a8..faac26d 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -3031,10 +3031,13 @@
                $logEntry->setComment( $reason );
                $logid = $logEntry->insert();
 
-               $dbw->onTransactionPreCommitOrIdle( function () use ( $dbw, 
$logEntry, $logid ) {
-                       // Bug 56776: avoid deadlocks (especially from 
FileDeleteForm)
-                       $logEntry->publish( $logid );
-               } );
+               $dbw->onTransactionPreCommitOrIdle(
+                       function () use ( $dbw, $logEntry, $logid ) {
+                               // Bug 56776: avoid deadlocks (especially from 
FileDeleteForm)
+                               $logEntry->publish( $logid );
+                       },
+                       __METHOD__
+               );
 
                $dbw->endAtomic( __METHOD__ );
 
@@ -3672,7 +3675,8 @@
                                                $cat->refreshCounts();
                                        }
                                }
-                       }
+                       },
+                       __METHOD__
                );
        }
 
diff --git a/includes/resourceloader/ResourceLoaderModule.php 
b/includes/resourceloader/ResourceLoaderModule.php
index 2351efd..3e94460 100644
--- a/includes/resourceloader/ResourceLoaderModule.php
+++ b/includes/resourceloader/ResourceLoaderModule.php
@@ -487,9 +487,12 @@
                                );
 
                                if ( $dbw->trxLevel() ) {
-                                       $dbw->onTransactionResolution( function 
() use ( &$scopeLock ) {
-                                               ScopedCallback::consume( 
$scopeLock ); // release after commit
-                                       } );
+                                       $dbw->onTransactionResolution(
+                                               function () use ( &$scopeLock ) 
{
+                                                       
ScopedCallback::consume( $scopeLock ); // release after commit
+                                               },
+                                               __METHOD__
+                                       );
                                }
                        }
                } catch ( Exception $e ) {
diff --git a/includes/revisiondelete/RevDelList.php 
b/includes/revisiondelete/RevDelList.php
index 48604e1..674846d 100644
--- a/includes/revisiondelete/RevDelList.php
+++ b/includes/revisiondelete/RevDelList.php
@@ -120,10 +120,13 @@
                }
 
                $dbw->startAtomic( __METHOD__ );
-               $dbw->onTransactionResolution( function () {
-                       // Release locks on commit or error
-                       $this->releaseItemLocks();
-               } );
+               $dbw->onTransactionResolution(
+                       function () {
+                               // Release locks on commit or error
+                               $this->releaseItemLocks();
+                       },
+                       __METHOD__
+               );
 
                $missing = array_flip( $this->ids );
                $this->clearFileOps();
diff --git a/includes/user/User.php b/includes/user/User.php
index 2af0324..0d06c7b 100644
--- a/includes/user/User.php
+++ b/includes/user/User.php
@@ -2358,7 +2358,8 @@
                        wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle(
                                function() use ( $cache, $key ) {
                                        $cache->delete( $key );
-                               }
+                               },
+                               __METHOD__
                        );
                }
        }
@@ -4927,9 +4928,12 @@
         * Deferred version of incEditCountImmediate()
         */
        public function incEditCount() {
-               wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle( function() {
-                       $this->incEditCountImmediate();
-               } );
+               wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle(
+                       function () {
+                               $this->incEditCountImmediate();
+                       },
+                       __METHOD__
+               );
        }
 
        /**
diff --git a/includes/user/UserRightsProxy.php 
b/includes/user/UserRightsProxy.php
index 09244a4..69bc503 100644
--- a/includes/user/UserRightsProxy.php
+++ b/includes/user/UserRightsProxy.php
@@ -273,15 +273,20 @@
         * Replaces User::touchUser()
         */
        function invalidateCache() {
-               $this->db->update( 'user',
+               $this->db->update(
+                       'user',
                        [ 'user_touched' => $this->db->timestamp() ],
                        [ 'user_id' => $this->id ],
-                       __METHOD__ );
+                       __METHOD__
+               );
 
                $wikiId = $this->db->getWikiID();
                $userId = $this->id;
-               $this->db->onTransactionPreCommitOrIdle( function() use ( 
$wikiId, $userId ) {
-                       User::purge( $wikiId, $userId );
-               } );
+               $this->db->onTransactionPreCommitOrIdle(
+                       function () use ( $wikiId, $userId ) {
+                               User::purge( $wikiId, $userId );
+                       },
+                       __METHOD__
+               );
        }
 }
diff --git a/tests/phpunit/includes/db/DatabaseTest.php 
b/tests/phpunit/includes/db/DatabaseTest.php
index e884640..d4be6e4 100644
--- a/tests/phpunit/includes/db/DatabaseTest.php
+++ b/tests/phpunit/includes/db/DatabaseTest.php
@@ -25,6 +25,7 @@
                }
                $this->db->restoreFlags( IDatabase::RESTORE_INITIAL );
        }
+
        /**
         * @covers DatabaseBase::dropTable
         */
@@ -231,7 +232,7 @@
 
        private function dropFunctions() {
                $this->db->query( 'DROP FUNCTION IF EXISTS mw_test_function'
-                               . ( $this->db->getType() == 'postgres' ? '()' : 
'' )
+                       . ( $this->db->getType() == 'postgres' ? '()' : '' )
                );
        }
 
@@ -247,26 +248,35 @@
                $db->setFlag( DBO_TRX );
                $called = false;
                $flagSet = null;
-               $db->onTransactionIdle( function() use ( $db, &$flagSet, 
&$called ) {
-                       $called = true;
-                       $flagSet = $db->getFlag( DBO_TRX );
-               } );
+               $db->onTransactionIdle(
+                       function () use ( $db, &$flagSet, &$called ) {
+                               $called = true;
+                               $flagSet = $db->getFlag( DBO_TRX );
+                       },
+                       __METHOD__
+               );
                $this->assertFalse( $flagSet, 'DBO_TRX off in callback' );
                $this->assertTrue( $db->getFlag( DBO_TRX ), 'DBO_TRX restored 
to default' );
                $this->assertTrue( $called, 'Callback reached' );
 
                $db->clearFlag( DBO_TRX );
                $flagSet = null;
-               $db->onTransactionIdle( function() use ( $db, &$flagSet ) {
-                       $flagSet = $db->getFlag( DBO_TRX );
-               } );
+               $db->onTransactionIdle(
+                       function () use ( $db, &$flagSet ) {
+                               $flagSet = $db->getFlag( DBO_TRX );
+                       },
+                       __METHOD__
+               );
                $this->assertFalse( $flagSet, 'DBO_TRX off in callback' );
                $this->assertFalse( $db->getFlag( DBO_TRX ), 'DBO_TRX restored 
to default' );
 
                $db->clearFlag( DBO_TRX );
-               $db->onTransactionIdle( function() use ( $db ) {
-                       $db->setFlag( DBO_TRX );
-               } );
+               $db->onTransactionIdle(
+                       function () use ( $db ) {
+                               $db->setFlag( DBO_TRX );
+                       },
+                       __METHOD__
+               );
                $this->assertFalse( $db->getFlag( DBO_TRX ), 'DBO_TRX restored 
to default' );
        }
 
@@ -276,7 +286,7 @@
                $db->clearFlag( DBO_TRX );
                $db->begin( __METHOD__ );
                $called = false;
-               $db->onTransactionResolution( function() use ( $db, &$called ) {
+               $db->onTransactionResolution( function () use ( $db, &$called ) 
{
                        $called = true;
                        $db->setFlag( DBO_TRX );
                } );
@@ -287,7 +297,7 @@
                $db->clearFlag( DBO_TRX );
                $db->begin( __METHOD__ );
                $called = false;
-               $db->onTransactionResolution( function() use ( $db, &$called ) {
+               $db->onTransactionResolution( function () use ( $db, &$called ) 
{
                        $called = true;
                        $db->setFlag( DBO_TRX );
                } );
@@ -302,7 +312,7 @@
        public function testTransactionListener() {
                $db = $this->db;
 
-               $db->setTransactionListener( 'ping', function() use ( $db, 
&$called ) {
+               $db->setTransactionListener( 'ping', function () use ( $db, 
&$called ) {
                        $called = true;
                } );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/311027
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3e240b2eb5c1f6a21f1bc974c3d28f5755c7451a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Parent5446 <tylerro...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to