jenkins-bot has submitted this change and it was merged. Change subject: Cache requested workflows in UrlGenerator ......................................................................
Cache requested workflows in UrlGenerator UrlGenerator often is requested to create multiple urls for the same workflow. Cache the loaded workflows instead of requesting them each and every time. Change-Id: Id2f8dfce05fa7798934832ba94cb75edc151a2dc --- M includes/UrlGenerator.php 1 file changed, 25 insertions(+), 5 deletions(-) Approvals: Werdna: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/UrlGenerator.php b/includes/UrlGenerator.php index c7011e1..91ce957 100644 --- a/includes/UrlGenerator.php +++ b/includes/UrlGenerator.php @@ -9,6 +9,21 @@ use Flow\Exception\InvalidInputException; class UrlGenerator { + /** + * @var OccupationController + */ + protected $occupationController; + + /** + * @var ObjectManager Workflow storage + */ + protected $storage; + + /** + * @var array Cached array of already loaded workflows + */ + protected $workflows = array(); + public function __construct( ObjectManager $workflowStorage, OccupationController $occupationController ) { $this->occupationController = $occupationController; $this->storage = $workflowStorage; @@ -87,7 +102,7 @@ if ( !$revision->isTopicTitle() ) { $data['topic[postId]'] = $revision->getPostId()->getHex(); } - + if ( $specificRevision ) { $data['topic[revId]'] = $revision->getRevisionId()->getHex(); } @@ -109,11 +124,16 @@ */ public function generateUrlData( $workflow, $action = 'view', array $query = array() ) { if ( ! $workflow instanceof Workflow ) { - $workflowId = $workflow; // Only way to know what title the workflow points at - $workflow = $this->storage->get( $workflowId ); - if ( !$workflow ) { - throw new InvalidInputException( 'Invalid workflow: ' . $workflowId, 'invalid-workflow' ); + $workflowId = $workflow; + if ( isset( $this->workflows[$workflowId->getHex()] ) ) { + $workflow = $this->workflows[$workflowId->getHex()]; + } else { + $workflow = $this->storage->get( $workflowId ); + if ( !$workflow ) { + throw new InvalidInputException( 'Invalid workflow: ' . $workflowId, 'invalid-workflow' ); + } + $this->workflows[$workflowId->getHex()] = $workflow; } } -- To view, visit https://gerrit.wikimedia.org/r/106475 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Id2f8dfce05fa7798934832ba94cb75edc151a2dc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Werdna <agarr...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits