MediaWiki  1.29.1
DeferredUpdates Class Reference

Class for managing the deferred updates. More...

Collaboration diagram for DeferredUpdates:

Static Public Member Functions

static addCallableUpdate ( $callable, $stage=self::POSTSEND, IDatabase $dbw=null)
 Add a callable update. More...
 
static addUpdate (DeferrableUpdate $update, $stage=self::POSTSEND)
 Add an update to the deferred list to be run later by execute() More...
 
static clearPendingUpdates ()
 Clear all pending updates without performing them. More...
 
static doUpdates ( $mode='run', $stage=self::ALL)
 Do any deferred updates and clear the list. More...
 
static getPendingUpdates ( $stage=self::ALL)
 
static pendingUpdatesCount ()
 
static setImmediateMode ( $value)
 
static tryOpportunisticExecute ( $mode='run')
 Run all deferred updates immediately if there are no DB writes active. More...
 

Public Attributes

const ALL = 0
 
const BIG_QUEUE_SIZE = 100
 
const POSTSEND = 2
 
const PRESEND = 1
 

Static Protected Member Functions

static execute (array &$queue, $mode, $stage)
 Immediately run/queue a list of updates. More...
 

Static Private Member Functions

static areDatabaseTransactionsActive ()
 
static enqueueUpdates (array $updates)
 Enqueue a job for each EnqueueableDataUpdate item and return the other items. More...
 
static push (array &$queue, DeferrableUpdate $update)
 
static runUpdate (DeferrableUpdate $update, LBFactory $lbFactory, $mode, $stage)
 

Static Private Attributes

static array null $executeContext
 Information about the current execute() call or null if not running. More...
 
static DeferrableUpdate[] $postSendUpdates = []
 Updates to be deferred until after request end. More...
 
static DeferrableUpdate[] $preSendUpdates = []
 Updates to be deferred until before request end. More...
 

Detailed Description

Class for managing the deferred updates.

In web request mode, deferred updates can be run at the end of the request, either before or after the HTTP response has been sent. In either case, they run after the DB commit step. If an update runs after the response is sent, it will not block clients. If sent before, it will run synchronously. These two modes are defined via PRESEND and POSTSEND constants, the latter being the default for addUpdate() and addCallableUpdate().

Updates that work through this system will be more likely to complete by the time the client makes their next request after this one than with the JobQueue system.

In CLI mode, updates run immediately if no DB writes are pending. Otherwise, they run when:

  • a) Any waitForReplication() call if no writes are pending on any DB
  • b) A commit happens on Maintenance::getDB( DB_MASTER ) if no writes are pending on any DB
  • c) EnqueueableDataUpdate tasks may enqueue on commit of Maintenance::getDB( DB_MASTER )
  • d) At the completion of Maintenance::execute()

When updates are deferred, they go into one two FIFO "top-queues" (one for pre-send and one for post-send). Updates enqueued during doUpdate() of a "top" update go into the "sub-queue" for that update. After that method finishes, the sub-queue is run until drained. This continues for each top-queue job until the entire top queue is drained. This happens for the pre-send top-queue, and later on, the post-send top-queue, in execute().

Since
1.19

Definition at line 53 of file DeferredUpdates.php.

Member Function Documentation

◆ addCallableUpdate()

static DeferredUpdates::addCallableUpdate (   $callable,
  $stage = self::POSTSEND,
IDatabase  $dbw = null 
)
static

Add a callable update.

In a lot of cases, we just need a callback/closure, defining a new DeferrableUpdate object is not necessary

See also
MWCallableUpdate::__construct()
Parameters
callable$callable
integer$stageDeferredUpdates constant (PRESEND or POSTSEND) (since 1.27)
IDatabase | null$dbwAbort if this DB is rolled back optional

Definition at line 111 of file DeferredUpdates.php.

References addUpdate(), and wfGetCaller().

Referenced by MediaWiki\Auth\AuthManager\autoCreateUser(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider\beginPrimaryAuthentication(), SpecialEditWatchlist\cleanupWatchlist(), User\clearNotification(), FileBackendMultiWrite\doDirectoryOp(), WikiPage\doEditContent(), SpamBlacklist\doLogging(), FileBackendMultiWrite\doOperationsInternal(), FileBackendMultiWrite\doQuickOperationsInternal(), SiteStatsUpdate\doUpdate(), EditPage\edit(), MovePageForm\execute(), JobRunner\executeJob(), CategoryViewer\getCountMessage(), MediaWiki\Logger\Monolog\BufferHandler\handle(), Category\initialize(), WikiPage\insertRedirect(), LocalFile\maybeUpgradeRow(), RecentChange\notifyEdit(), RecentChange\notifyNew(), WikiPage\onArticleEdit(), ManualLogEntry\publish(), MessageCache\replace(), MediaWiki\restInPeace(), MediaWiki\Session\SessionBackend\save(), SpecialSearch\saveNamespaces(), Pingback\schedulePingback(), RevDelList\setVisibility(), DeferredUpdatesTest\testDoUpdatesCLI(), DeferredUpdatesTest\testDoUpdatesWeb(), DeferredUpdatesTest\testPresendAddOnPostsendRun(), WatchedItemStore\updateNotificationTimestamp(), and EditPage\updateWatchlist().

◆ addUpdate()

static DeferredUpdates::addUpdate ( DeferrableUpdate  $update,
  $stage = self::POSTSEND 
)
static

Add an update to the deferred list to be run later by execute()

In CLI mode, callback magic will also be used to run updates when safe

Parameters
DeferrableUpdate$updateSome object that implements doUpdate()
integer$stageDeferredUpdates constant (PRESEND or POSTSEND) (since 1.27)

Definition at line 76 of file DeferredUpdates.php.

References $wgCommandLineMode, global, push(), and tryOpportunisticExecute().

Referenced by addCallableUpdate(), MediaWiki\Auth\AuthManager\autoCreateUser(), User\clearAllNotifications(), MediaWiki\Auth\AuthManager\continueAccountCreation(), LocalFile\delete(), LocalFile\deleteOld(), JobQueueDB\doBatchPush(), WikiPage\doCreate(), WikiPage\doDeleteUpdates(), WikiPage\doEditUpdates(), WikiPage\doModify(), RevDelFileList\doPostCommitUpdates(), WikiFilePage\doPurge(), WikiPage\doPurge(), ApiPurge\execute(), ChangesListSpecialPage\execute(), LocalFileRestoreBatch\execute(), WikiImporter\finishImportPage(), RefreshLinks\fixLinksFromArticle(), Title\invalidateCache(), LinksUpdate\invalidateProperties(), NamespaceConflictChecker\mergePage(), MovePage\move(), LocalFile\move(), WikiPage\onArticleCreate(), WikiPage\onArticleDelete(), WikiPage\onArticleEdit(), LocalFile\purgeCache(), File\purgeEverything(), UserGroupMembership\purgeExpired(), Block\purgeExpired(), Title\purgeExpiredRestrictions(), LocalFile\purgeOldThumbnails(), Title\purgeSquid(), LocalFile\purgeThumbnails(), LocalFile\recordUpload2(), DeferredUpdatesTest\testGetPendingUpdates(), CdnCacheUpdateTest\testPurgeMergeWeb(), Title\touchLinks(), and PageArchive\undeleteRevisions().

◆ areDatabaseTransactionsActive()

static DeferredUpdates::areDatabaseTransactionsActive ( )
staticprivate
Returns
bool If a transaction round is active or connection is not ready for commit()

Definition at line 359 of file DeferredUpdates.php.

References $lbFactory, Wikimedia\Rdbms\IDatabase\explicitTrxActive(), Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), use, and Wikimedia\Rdbms\IDatabase\writesOrCallbacksPending().

◆ clearPendingUpdates()

static DeferredUpdates::clearPendingUpdates ( )
static

Clear all pending updates without performing them.

Generally, you don't want or need to call this. Unit tests need it though.

Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 351 of file DeferredUpdates.php.

Referenced by UploadFromUrlTestSuite\setUp(), MediaWikiTestCase\setUp(), and DeferredUpdatesTest\testGetPendingUpdates().

◆ doUpdates()

static DeferredUpdates::doUpdates (   $mode = 'run',
  $stage = self::ALL 
)
static

Do any deferred updates and clear the list.

Parameters
string$modeUse "enqueue" to use the job queue when possible [Default: "run"]
integer$stageDeferredUpdates constant (PRESEND, POSTSEND, or ALL) (since 1.27)

Definition at line 123 of file DeferredUpdates.php.

References ALL, and execute().

Referenced by JobRunner\executeJob(), RefreshLinks\fixLinksFromArticle(), NamespaceConflictChecker\mergePage(), MediaWiki\preOutputCommit(), MediaWiki\restInPeace(), FileBackendTest\testAsyncWrites(), DeferredUpdatesTest\testDoUpdatesCLI(), DeferredUpdatesTest\testDoUpdatesWeb(), DeferredUpdatesTest\testPresendAddOnPostsendRun(), BagOStuffTest\testReportDupes(), and tryOpportunisticExecute().

◆ enqueueUpdates()

static DeferredUpdates::enqueueUpdates ( array  $updates)
staticprivate

Enqueue a job for each EnqueueableDataUpdate item and return the other items.

Parameters
DeferrableUpdate[]$updatesA list of deferred update instances
Returns
DeferrableUpdate[] Remaining updates that do not support being queued

Definition at line 309 of file DeferredUpdates.php.

References as, and JobQueueGroup\singleton().

Referenced by tryOpportunisticExecute().

◆ execute()

static DeferredUpdates::execute ( array $queue,
  $mode,
  $stage 
)
staticprotected

Immediately run/queue a list of updates.

Parameters
DeferrableUpdate[]&$queueList of DeferrableUpdate objects
string$modeUse "enqueue" to use the job queue when possible
integer$stageClass constant (PRESEND, POSTSEND) (since 1.28)
Exceptions
ErrorPageErrorHappens on top-level calls
ExceptionHappens on second-level calls

Definition at line 172 of file DeferredUpdates.php.

References $lbFactory, $name, $queue, $services, as, RequestContext\getMain(), key, and runUpdate().

Referenced by doUpdates().

◆ getPendingUpdates()

static DeferredUpdates::getPendingUpdates (   $stage = self::ALL)
static
Parameters
integer$stageDeferredUpdates constant (PRESEND, POSTSEND, or ALL)
Since
1.29

Definition at line 336 of file DeferredUpdates.php.

Referenced by DeferredUpdatesTest\testGetPendingUpdates().

◆ pendingUpdatesCount()

static DeferredUpdates::pendingUpdatesCount ( )
static
Returns
integer Number of enqueued updates
Since
1.28

Definition at line 328 of file DeferredUpdates.php.

References captcha-old\count.

Referenced by EditPageTest\testCreatePageTrx(), DeferredUpdatesTest\testDoUpdatesWeb(), MessageCacheTest\testReplaceMsg(), and tryOpportunisticExecute().

◆ push()

static DeferredUpdates::push ( array $queue,
DeferrableUpdate  $update 
)
staticprivate
Parameters
DeferrableUpdate[]$queue
DeferrableUpdate$update

Definition at line 148 of file DeferredUpdates.php.

References $queue.

Referenced by addUpdate().

◆ runUpdate()

static DeferredUpdates::runUpdate ( DeferrableUpdate  $update,
LBFactory  $lbFactory,
  $mode,
  $stage 
)
staticprivate
Parameters
DeferrableUpdate$update
LBFactory$lbFactory
string$mode
integer$stage
Returns
ErrorPageError|null

Definition at line 244 of file DeferredUpdates.php.

References $e, $lbFactory, DeferrableUpdate\doUpdate(), MWExceptionHandler\rollbackMasterChangesAndLog(), and JobQueueGroup\singleton().

Referenced by execute().

◆ setImmediateMode()

static DeferredUpdates::setImmediateMode (   $value)
static
Parameters
bool$valueWhether to just immediately run updates in addUpdate()
Since
1.28
Deprecated:
1.29 Causes issues in Web-executed jobs - see T165714 and T100085.

Definition at line 140 of file DeferredUpdates.php.

References wfDeprecated().

◆ tryOpportunisticExecute()

static DeferredUpdates::tryOpportunisticExecute (   $mode = 'run')
static

Run all deferred updates immediately if there are no DB writes active.

If $mode is 'run' but there are busy databates, EnqueueableDataUpdate tasks will be enqueued anyway for the sake of progress.

Parameters
string$modeUse "enqueue" to use the job queue when possible
Returns
bool Whether updates were allowed to run
Since
1.28

Definition at line 281 of file DeferredUpdates.php.

References doUpdates(), enqueueUpdates(), and pendingUpdatesCount().

Referenced by addUpdate(), and Maintenance\setLBFactoryTriggers().

Member Data Documentation

◆ $executeContext

array null DeferredUpdates::$executeContext
staticprivate

Information about the current execute() call or null if not running.

Definition at line 66 of file DeferredUpdates.php.

◆ $postSendUpdates

DeferrableUpdate [] DeferredUpdates::$postSendUpdates = []
staticprivate

Updates to be deferred until after request end.

Definition at line 57 of file DeferredUpdates.php.

◆ $preSendUpdates

DeferrableUpdate [] DeferredUpdates::$preSendUpdates = []
staticprivate

Updates to be deferred until before request end.

Definition at line 55 of file DeferredUpdates.php.

◆ ALL

const DeferredUpdates::ALL = 0

Definition at line 59 of file DeferredUpdates.php.

Referenced by doUpdates(), and DeferredUpdatesTest\testGetPendingUpdates().

◆ BIG_QUEUE_SIZE

const DeferredUpdates::BIG_QUEUE_SIZE = 100

Definition at line 63 of file DeferredUpdates.php.

◆ POSTSEND

◆ PRESEND


The documentation for this class was generated from the following file: