*/
class DeferredUpdates {
/** @var DeferrableUpdate[] Updates to be deferred until before request end */
- private static $preSendUpdates = array();
+ private static $preSendUpdates = [];
/** @var DeferrableUpdate[] Updates to be deferred until after request end */
- private static $postSendUpdates = array();
+ private static $postSendUpdates = [];
const ALL = 0; // all updates
const PRESEND = 1; // for updates that should run before flushing output buffer
}
/**
- * Add a callable update. In a lot of cases, we just need a callback/closure,
+ * Add a callable update. In a lot of cases, we just need a callback/closure,
* defining a new DeferrableUpdate object is not necessary
*
* @see MWCallableUpdate::__construct()
* @param integer $type DeferredUpdates constant (PRESEND or POSTSEND) (since 1.27)
*/
public static function addCallableUpdate( $callable, $type = self::POSTSEND ) {
- self::addUpdate( new MWCallableUpdate( $callable ), $type );
+ self::addUpdate( new MWCallableUpdate( $callable, wfGetCaller() ), $type );
}
/**
}
public static function execute( array &$queue, $mode ) {
- $updates = $queue; // snapshot of queue
+ $stats = \MediaWiki\MediaWikiServices::getInstance()->getStatsdDataFactory();
+ $method = RequestContext::getMain()->getRequest()->getMethod();
+ $updates = $queue; // snapshot of queue
// Keep doing rounds of updates until none get enqueued
while ( count( $updates ) ) {
- $queue = array(); // clear the queue
+ $queue = []; // clear the queue
/** @var DataUpdate[] $dataUpdates */
- $dataUpdates = array();
+ $dataUpdates = [];
/** @var DeferrableUpdate[] $otherUpdates */
- $otherUpdates = array();
+ $otherUpdates = [];
foreach ( $updates as $update ) {
if ( $update instanceof DataUpdate ) {
$dataUpdates[] = $update;
} else {
$otherUpdates[] = $update;
}
+
+ $name = $update instanceof DeferrableCallback
+ ? get_class( $update ) . '-' . $update->getOrigin()
+ : get_class( $update );
+ $stats->increment( 'deferred_updates.' . $method . '.' . $name );
}
// Delegate DataUpdate execution to the DataUpdate class
- DataUpdate::runUpdates( $dataUpdates, $mode );
+ try {
+ DataUpdate::runUpdates( $dataUpdates, $mode );
+ } catch ( Exception $e ) {
+ // Let the other updates occur if these had to rollback
+ MWExceptionHandler::logException( $e );
+ }
// Execute the non-DataUpdate tasks
foreach ( $otherUpdates as $update ) {
try {
$update->doUpdate();
- wfGetLBFactory()->commitMasterChanges();
+ wfGetLBFactory()->commitMasterChanges( __METHOD__ );
} catch ( Exception $e ) {
// We don't want exceptions thrown during deferred updates to
// be reported to the user since the output is already sent
}
// Make sure incomplete transactions are not committed and end any
// open atomic sections so that other DB updates have a chance to run
- wfGetLBFactory()->rollbackMasterChanges();
+ wfGetLBFactory()->rollbackMasterChanges( __METHOD__ );
}
}
* want or need to call this. Unit tests need it though.
*/
public static function clearPendingUpdates() {
- self::$preSendUpdates = array();
- self::$postSendUpdates = array();
+ self::$preSendUpdates = [];
+ self::$postSendUpdates = [];
}
}