3 * Interface that deferrable updates should implement. Basically required so we
4 * can validate input on DeferredUpdates::addUpdate()
8 interface DeferrableUpdate
{
10 * Perform the actual work
16 * Class for mananging the deferred updates.
20 class DeferredUpdates
{
22 * Store of updates to be deferred until the end of the request.
24 private static $updates = array();
27 * Add an update to the deferred list
28 * @param $update DeferrableUpdate Some object that implements doUpdate()
30 public static function addUpdate( DeferrableUpdate
$update ) {
31 array_push( self
::$updates, $update );
35 * HTMLCacheUpdates are the most common deferred update people use. This
36 * is a shortcut method for that.
37 * @see HTMLCacheUpdate::__construct()
39 public static function addHTMLCacheUpdate( $title, $table ) {
40 self
::addUpdate( new HTMLCacheUpdate( $title, $table ) );
44 * Do any deferred updates and clear the list
46 * @param $commit String: set to 'commit' to commit after every update to
47 * prevent lock contention
49 public static function doUpdates( $commit = '' ) {
50 global $wgDeferredUpdateList;
52 wfProfileIn( __METHOD__
);
54 $updates = array_merge( $wgDeferredUpdateList, self
::$updates );
56 // No need to get master connections in case of empty updates array
57 if ( !count( $updates ) ) {
58 wfProfileOut( __METHOD__
);
62 $doCommit = $commit == 'commit';
64 $dbw = wfGetDB( DB_MASTER
);
67 foreach ( $updates as $update ) {
70 if ( $doCommit && $dbw->trxLevel() ) {
75 self
::clearPendingUpdates();
76 wfProfileOut( __METHOD__
);
80 * Clear all pending updates without performing them. Generally, you don't
81 * want or need to call this. Unit tests need it though.
83 public static function clearPendingUpdates() {
84 global $wgDeferredUpdateList;
85 $wgDeferredUpdateList = self
::$updates = array();