Aaron Schulz has submitted this change and it was merged.

Change subject: Add AtomicSectionUpdate deferred update class
......................................................................


Add AtomicSectionUpdate deferred update class

This makes it easier to have deferred atomic DB transactions

Bug: T122115
Change-Id: I67afe335f03cc21fdce78abdf3f31fa67a368419
---
M autoload.php
M includes/Block.php
M includes/Title.php
A includes/deferred/AtomicSectionUpdate.php
4 files changed, 62 insertions(+), 20 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/autoload.php b/autoload.php
index 7dec6b7..a25b562 100644
--- a/autoload.php
+++ b/autoload.php
@@ -140,6 +140,7 @@
        '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 7b287dc..c017c6c 100644
--- a/includes/Block.php
+++ b/includes/Block.php
@@ -1021,12 +1021,17 @@
                        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 56ba4c7..5b86ed6 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -3020,20 +3020,22 @@
                        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 0000000..a9921b3
--- /dev/null
+++ b/includes/deferred/AtomicSectionUpdate.php
@@ -0,0 +1,34 @@
+<?php
+
+/**
+ * Deferrable Update for closure/callback updates via 
IDatabase::doAtomicSection()
+ * @since 1.27
+ */
+class AtomicSectionUpdate implements DeferrableUpdate {
+       /** @var IDatabase */
+       private $dbw;
+       /** @var string */
+       private $fname;
+       /** @var Closure|callable */
+       private $callback;
+
+       /**
+        * @param IDatabase $dbw
+        * @param string $fname Caller name (usually __METHOD__)
+        * @param callable $callback
+        * @throws InvalidArgumentException
+        * @see IDatabase::doAtomicSection()
+        */
+       public function __construct( IDatabase $dbw, $fname, $callback ) {
+               $this->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 );
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/263867
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I67afe335f03cc21fdce78abdf3f31fa67a368419
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to