51 $this->activeUpdate = $update;
53 $this->queueByStage = array_fill_keys( DeferredUpdates::STAGES, [] );
60 return new self(
null,
null, null );
94 $stageEffective = max( $stage, $this->activeStage );
96 $queue =& $this->queueByStage[$stageEffective];
99 $class = get_class( $update );
100 if ( isset(
$queue[$class] ) ) {
102 $existingUpdate =
$queue[$class];
103 '@phan-var MergeableUpdate $existingUpdate';
104 $existingUpdate->merge( $update );
108 $queue[$class] = $existingUpdate;
123 return array_sum( array_map(
'count', $this->queueByStage ) );
133 $matchingQueues = [];
134 foreach ( $this->queueByStage as $queueStage =>
$queue ) {
135 if ( $stage === DeferredUpdates::ALL || $stage === $queueStage ) {
136 $matchingQueues[] =
$queue;
140 return array_merge( ...$matchingQueues );
147 $this->queueByStage = array_fill_keys( array_keys( $this->queueByStage ), [] );
159 $claimedUpdates = [];
160 foreach ( $this->queueByStage as $queueStage =>
$queue ) {
161 if ( $stage === DeferredUpdates::ALL || $stage === $queueStage ) {
162 foreach (
$queue as $k => $update ) {
163 if ( $update instanceof $class ) {
164 $claimedUpdates[] = $update;
165 unset( $this->queueByStage[$queueStage][$k] );
171 foreach ( $claimedUpdates as $update ) {
172 $callback( $update );
185 if ( $stage === DeferredUpdates::ALL ) {
187 $activeStage = DeferredUpdates::STAGES[count( DeferredUpdates::STAGES ) - 1];
195 foreach ( range( DeferredUpdates::STAGES[0],
$activeStage ) as $queueStage ) {
198 }
while ( $processed > 0 );
214 if ( !$this->parentScope ) {
218 foreach ( $this->queueByStage as $queueStage =>
$queue ) {
219 foreach (
$queue as $k => $update ) {
221 unset( $this->queueByStage[$queueStage][$k] );
222 $this->parentScope->addUpdate( $update, $queueStage );
241 $claimedUpdates = $this->queueByStage[$stage];
242 $this->queueByStage[$stage] = [];
245 while ( $claimedUpdates ) {
251 $claimedDataUpdates = [];
252 $claimedGenericUpdates = [];
253 foreach ( $claimedUpdates as $claimedUpdate ) {
255 $claimedDataUpdates[] = $claimedUpdate;
257 $claimedGenericUpdates[] = $claimedUpdate;
263 foreach ( $claimedDataUpdates as $claimedDataUpdate ) {
266 foreach ( $claimedGenericUpdates as $claimedGenericUpdate ) {
271 $claimedUpdates = $this->queueByStage[$stage];
272 $this->queueByStage[$stage] = [];
Abstract base class for update jobs that do something with some secondary data extracted from article...
DeferredUpdates helper class for managing DeferrableUpdate::doUpdate() nesting levels caused by neste...
consumeMatchingUpdates( $stage, $class, callable $callback)
Remove pending updates of the specified stage/class and pass them to a callback.
int null $activeStage
Active processing stage in DeferredUpdates::STAGES (if any)
DeferredUpdatesScope null $parentScope
Parent scope (root scope as none)
static newChildScope( $activeStage, DeferrableUpdate $update, DeferredUpdatesScope $parentScope)
pendingUpdatesCount()
Get the number of pending updates within this scope.
addUpdate(DeferrableUpdate $update, $stage)
Enqueue a deferred update within this scope using the specified "defer until" time.
getPendingUpdates( $stage)
Get pending updates within this scope with the given "defer until" stage.
processUpdates( $stage, callable $callback)
Iteratively, reassign unready pending updates to the parent scope (if applicable) and process the rea...
DeferrableUpdate[][] $queueByStage
Stage-ordered (stage => merge class or position => update) map.
processStageQueue( $stage, $activeStage, callable $callback)
DeferrableUpdate null $activeUpdate
Deferred update that owns this scope (root scope has none)
clearPendingUpdates()
Cancel all pending updates within this scope.
__construct( $activeStage, ?DeferrableUpdate $update, ?DeferredUpdatesScope $parentScope)
upmergeUnreadyUpdates( $activeStage)
If this is a child scope, then reassign unready pending updates to the parent scope:
getActiveUpdate()
Get the deferred update that owns this scope (root scope has none)
Interface that deferrable updates should implement.
Interface that deferrable updates can implement to signal that updates can be combined.