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