EBernhardson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/164660

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(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/60/164660/1

diff --git a/container.php b/container.php
index 9b7a83b..bd192d2 100644
--- a/container.php
+++ b/container.php
@@ -172,6 +172,7 @@
 
        return new Flow\Data\Listener\OccupationListener(
                $c['occupation_controller'],
+               $c['deferred_queue'],
                $wgFlowDefaultWorkflow
        );
 } );
@@ -564,6 +565,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: newchange
Gerrit-Change-Id: I9bad5d2def0f58bc9cc1751a648ee54bfbcbf4c1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>

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

Reply via email to