From: Aaron Schulz Date: Wed, 13 Jan 2016 16:54:48 +0000 (-0800) Subject: Add AtomicSectionUpdate deferred update class X-Git-Tag: 1.31.0-rc.0~8341 X-Git-Url: http://git.cyclocoop.org///%22%40url%40//%22?a=commitdiff_plain;h=ec63f72c79bad9567aa7f5b1c0d205436ad52d75;p=lhc%2Fweb%2Fwiklou.git Add AtomicSectionUpdate deferred update class This makes it easier to have deferred atomic DB transactions Bug: T122115 Change-Id: I67afe335f03cc21fdce78abdf3f31fa67a368419 --- diff --git a/autoload.php b/autoload.php index 7dec6b7a35..a25b562d08 100644 --- a/autoload.php +++ b/autoload.php @@ -140,6 +140,7 @@ $wgAutoloadLocalClasses = array( 'Article' => __DIR__ . '/includes/page/Article.php', 'AssembleUploadChunksJob' => __DIR__ . '/includes/jobqueue/jobs/AssembleUploadChunksJob.php', 'AtomFeed' => __DIR__ . '/includes/Feed.php', + 'AtomicSectionUpdate' => __DIR__ . '/includes/deferred/AtomicSectionUpdate.php', 'AttachLatest' => __DIR__ . '/maintenance/attachLatest.php', 'AuthPlugin' => __DIR__ . '/includes/AuthPlugin.php', 'AuthPluginUser' => __DIR__ . '/includes/AuthPlugin.php', diff --git a/includes/Block.php b/includes/Block.php index 7b287dc030..c017c6c9b7 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -1021,12 +1021,17 @@ class Block { return; } - $method = __METHOD__; - $dbw = wfGetDB( DB_MASTER ); - $dbw->onTransactionIdle( function () use ( $dbw, $method ) { - $dbw->delete( 'ipblocks', - array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), $method ); - } ); + DeferredUpdates::addUpdate( new AtomicSectionUpdate( + wfGetDB( DB_MASTER ), + __METHOD__, + function ( IDatabase $dbw, $fname ) { + $dbw->delete( + 'ipblocks', + array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), + $fname + ); + } + ) ); } /** diff --git a/includes/Title.php b/includes/Title.php index 56ba4c7781..5b86ed6f68 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -3020,20 +3020,22 @@ class Title { return; } - $method = __METHOD__; - $dbw = wfGetDB( DB_MASTER ); - $dbw->onTransactionIdle( function () use ( $dbw, $method ) { - $dbw->delete( - 'page_restrictions', - array( 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), - $method - ); - $dbw->delete( - 'protected_titles', - array( 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), - $method - ); - } ); + DeferredUpdates::addUpdate( new AtomicSectionUpdate( + wfGetDB( DB_MASTER ), + __METHOD__, + function ( IDatabase $dbw, $fname ) { + $dbw->delete( + 'page_restrictions', + array( 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), + $fname + ); + $dbw->delete( + 'protected_titles', + array( 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), + $fname + ); + } + ) ); } /** diff --git a/includes/deferred/AtomicSectionUpdate.php b/includes/deferred/AtomicSectionUpdate.php new file mode 100644 index 0000000000..a9921b3242 --- /dev/null +++ b/includes/deferred/AtomicSectionUpdate.php @@ -0,0 +1,34 @@ +dbw = $dbw; + $this->fname = $fname; + if ( !is_callable( $callback ) ) { + throw new InvalidArgumentException( 'Not a valid callback/closure!' ); + } + $this->callback = $callback; + } + + public function doUpdate() { + $this->dbw->doAtomicSection( $this->fname, $this->callback ); + } +}