jenkins-bot has submitted this change and it was merged.

Change subject: Hygiene: Push page creation to DeferredUpdates
......................................................................


Hygiene: Push page creation to DeferredUpdates

In a followup patch to this I add tests to run the flow API
directly, one issue that was run into is that the doEditPage call
within the controller starts and ends a transaction, but we are
currently within the flow transaction and don't want that closed
yet.  As such push the update into the deferred updates, using
the queue so it only happens when the commit succedes.

Additionally this call to the occupation controller is responsible
for 15-20% of the runtime of a new-topic action. This wont likely
help API consumers, i believe the xhr code is waiting for the request
to complete, but browsers submitting the form directly should get
their response on screen faster.

Change-Id: I9bad5d2def0f58bc9cc1751a648ee54bfbcbf4c1
---
M container.php
M includes/Data/Listener/OccupationListener.php
2 files changed, 21 insertions(+), 5 deletions(-)

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



diff --git a/container.php b/container.php
index 23050fa..1a2d90a 100644
--- a/container.php
+++ b/container.php
@@ -176,6 +176,7 @@
 
        return new Flow\Data\Listener\OccupationListener(
                $c['occupation_controller'],
+               $c['deferred_queue'],
                $wgFlowDefaultWorkflow
        );
 } );
@@ -571,6 +572,8 @@
        );
 } );
 
+// Queue of callbacks to run by DeferredUpdates, but only
+// on successfull commit
 $c['deferred_queue'] = $c->share( function( $c ) {
        return new SplQueue;
 } );
diff --git a/includes/Data/Listener/OccupationListener.php 
b/includes/Data/Listener/OccupationListener.php
index 5d209b5..0da2900 100644
--- a/includes/Data/Listener/OccupationListener.php
+++ b/includes/Data/Listener/OccupationListener.php
@@ -6,6 +6,7 @@
 use Flow\Data\LifecycleHandler;
 use Flow\Model\Workflow;
 use Flow\OccupationController;
+use SplQueue;
 
 /**
  * Ensures that a given workflow is occupied.  This will be unnecssary
@@ -15,6 +16,9 @@
        /** @var OccupationController **/
        protected $occupationController;
 
+       /** @var SplQueue */
+       protected $deferredQueue;
+
        /** @var string **/
        protected $defaultType;
 
@@ -23,10 +27,16 @@
 
        /**
         * @param OccupationController $occupationController The 
OccupationController to occupy the page with.
+        * @param SplQueue             $deferredQueue        Queue of callbacks 
to run only if commit succedes
         * @param string               $defaultType          The workflow type 
to look for
         */
-       public function __construct( OccupationController 
$occupationController, $defaultType ) {
+       public function __construct(
+               OccupationController $occupationController,
+               SplQueue $deferredQueue,
+               $defaultType
+       ) {
                $this->occupationController = $occupationController;
+               $this->deferredQueue = $deferredQueue;
                $this->defaultType = $defaultType;
        }
 
@@ -52,10 +62,13 @@
 
        protected function ensureOccupation( Workflow $workflow ) {
                if ( $this->enabled ) {
-                       $this->occupationController->ensureFlowRevision(
-                               new Article( $workflow->getArticleTitle() ),
-                               $workflow
-                       );
+                       $controller = $this->occupationController;
+                       $this->deferredQueue->push( function() use ( 
$controller, $workflow ) {
+                               $controller->ensureFlowRevision(
+                                       new Article( 
$workflow->getArticleTitle() ),
+                                       $workflow
+                               );
+                       } );
                }
        }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9bad5d2def0f58bc9cc1751a648ee54bfbcbf4c1
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: SG <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to