Include the method that made the callback in the key.
Change-Id: Ifc7c486ee5c8d57b2516456569bb724cf7dc2b99
'DateFormats' => __DIR__ . '/maintenance/language/date-formats.php',
'DateFormatter' => __DIR__ . '/includes/parser/DateFormatter.php',
'DeadendPagesPage' => __DIR__ . '/includes/specials/SpecialDeadendpages.php',
+ 'DeferrableCallback' => __DIR__ . '/includes/deferred/DeferrableCallback.php',
'DeferrableUpdate' => __DIR__ . '/includes/deferred/DeferrableUpdate.php',
'DeferredStringifier' => __DIR__ . '/includes/libs/DeferredStringifier.php',
'DeferredUpdates' => __DIR__ . '/includes/deferred/DeferredUpdates.php',
* Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
* @since 1.27
*/
-class AtomicSectionUpdate implements DeferrableUpdate {
+class AtomicSectionUpdate implements DeferrableUpdate, DeferrableCallback {
/** @var IDatabase */
private $dbw;
/** @var string */
$this->callback = null;
}
}
+
+ public function getOrigin() {
+ return $this->fname;
+ }
}
* Deferrable Update for closure/callback updates that should use auto-commit mode
* @since 1.28
*/
-class AutoCommitUpdate implements DeferrableUpdate {
+class AutoCommitUpdate implements DeferrableUpdate, DeferrableCallback {
/** @var IDatabase */
private $dbw;
/** @var string */
$this->callback = null;
}
}
+
+ public function getOrigin() {
+ return $this->fname;
+ }
}
/**
* Deferrable Update for closure/callback
*/
-class MWCallableUpdate implements DeferrableUpdate {
- /** @var Closure|callable */
+class MWCallableUpdate implements DeferrableUpdate, DeferrableCallback {
+ /** @var callable */
private $callback;
+ /** @var string */
+ private $fname;
/**
* @param callable $callback
- * @throws InvalidArgumentException
+ * @param string $fname Calling method
*/
- public function __construct( $callback ) {
- if ( !is_callable( $callback ) ) {
- throw new InvalidArgumentException( 'Not a valid callback/closure!' );
- }
+ public function __construct( callable $callback, $fname = 'unknown' ) {
$this->callback = $callback;
+ $this->fname = $fname;
}
public function doUpdate() {
call_user_func( $this->callback );
}
+
+ public function getOrigin() {
+ return $this->fname;
+ }
}
--- /dev/null
+<?php
+
+/**
+ * Callback wrapper that has an originating method
+ *
+ * @since 1.28
+ */
+interface DeferrableCallback {
+ /**
+ * @return string Originating method name
+ */
+ function getOrigin();
+}
}
/**
- * 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 );
}
/**
} else {
$otherUpdates[] = $update;
}
- $stats->increment( 'deferred_updates.' . $method . '.' . get_class( $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