jenkins-bot has submitted this change and it was merged.
Change subject: Only load the container on flow pages
......................................................................
Only load the container on flow pages
Profiling was showing flow code taking longer than other extensions
to initialize. To reduce the amount of code run on non-flow pages
I have pulled two variables out of the container and initialized
them in FlowHooks from the extension initialization. This brings
flow in-line with other extensions in the time it takes to initialize.
Change-Id: Ief1490edd04c82ebe1eab7b13aaa2ba6da78b73f
---
M Hooks.php
M container.php
M includes/Notifications/Controller.php
M includes/SpamFilter/Controller.php
4 files changed, 81 insertions(+), 37 deletions(-)
Approvals:
Matthias Mullie: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Hooks.php b/Hooks.php
index 27fef73..a53a06d 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -3,31 +3,82 @@
use Flow\Container;
use Flow\Exception\FlowException;
use Flow\Model\UUID;
+use Flow\Notification\NotificationController;
+use Flow\OccupationController;
+use Flow\SpamFilter\AbuseFilter;
+use Flow\TalkpageManager;
class FlowHooks {
+ /**
+ * @var OccupationController Initialized during extension intialization
+ */
+ protected static $occupationController;
+
+ /**
+ * @var AbuseFilter Initialized during extension initialization
+ */
+ protected static $abuseFilter;
+
+ /**
+ * Initialized during extension initialization rather than
+ * in container so that non-flow pages don't load the container.
+ *
+ * @return OccupationController
+ */
+ public static function getOccupationController() {
+ if ( self::$occupationController === null ) {
+ global $wgFlowOccupyNamespaces,
+ $wgFlowOccupyPages;
+
+ self::$occupationController = new TalkpageManager(
+ $wgFlowOccupyNamespaces,
+ $wgFlowOccupyPages
+ );
+ }
+ return self::$occupationController;
+ }
+
+ /**
+ * Initialized during extension initialization rather than
+ * in container so that non-flow pages don't load the container.
+ *
+ * @return AbuseFilter|null when disabled
+ */
+ public static function getAbuseFilter() {
+ if ( self::$abuseFilter === null ) {
+ global $wgUser,
+ $wgEchoNotifications,
+ $wgFlowAbuseFilterGroup,
+ $wgFlowAbuseFilterEmergencyDisableThreshold,
+ $wgFlowAbuseFilterEmergencyDisableCount,
+ $wgFlowAbuseFilterEmergencyDisableAge;
+
+ self::$abuseFilter = new AbuseFilter( $wgUser,
$wgFlowAbuseFilterGroup );
+ self::$abuseFilter->setup( array(
+ 'threshold' =>
$wgFlowAbuseFilterEmergencyDisableThreshold,
+ 'count' =>
$wgFlowAbuseFilterEmergencyDisableCount,
+ 'age' => $wgFlowAbuseFilterEmergencyDisableAge,
+ ) );
+ }
+ return self::$abuseFilter;
+ }
+
/**
* Initialize Flow extension with necessary data, this function is
invoked
* from $wgExtensionFunctions
*/
public static function initFlowExtension() {
- global $wgEchoNotifications,
- $wgFlowAbuseFilterGroup,
- $wgFlowAbuseFilterEmergencyDisableThreshold,
- $wgFlowAbuseFilterEmergencyDisableCount,
- $wgFlowAbuseFilterEmergencyDisableAge;
+ // needed to determine if a page is occupied by flow
+ self::getOccupationController();
+ // necessary to render flow notifications
if ( isset( $wgEchoNotifications ) ) {
- Container::get( 'controller.notification' )->setup();
+ NotificationController::setup();
}
+ // necessary to provide flow options in abuse filter on-wiki
pages
if ( $wgFlowAbuseFilterGroup ) {
- Container::get( 'controller.abusefilter' )->setup(
- array(
- 'threshold' =>
$wgFlowAbuseFilterEmergencyDisableThreshold,
- 'count' =>
$wgFlowAbuseFilterEmergencyDisableCount,
- 'age' =>
$wgFlowAbuseFilterEmergencyDisableAge,
- )
- );
+ self::getAbuseFilter();
}
}
@@ -168,12 +219,10 @@
*/
public static function onPerformAction( $output, $article, $title,
$user, $request, $wiki ) {
global $wgFlowCoreActionWhitelist;
- $container = Container::getContainer();
- $occupationController = $container['occupation_controller'];
$action = $wiki->getAction();
- if ( $occupationController->isTalkpageOccupied( $title ) &&
!in_array( $action, $wgFlowCoreActionWhitelist ) ) {
-
+ if ( self::$occupationController->isTalkpageOccupied( $title )
&& !in_array( $action, $wgFlowCoreActionWhitelist ) ) {
+ $container = Container::getContainer();
$view = new Flow\View(
$container['templating'],
$container['url_generator'],
@@ -189,7 +238,7 @@
if ( !$loader->getWorkflow()->isNew() ) {
// Workflow currently exists, make sure
a revision also exists
-
$occupationController->ensureFlowRevision( $article );
+
self::$occupationController->ensureFlowRevision( $article );
}
$view->show( $loader, $action );
@@ -217,11 +266,8 @@
$title = $template->getTitle();
- $container = Container::getContainer();
- $occupationController = $container['occupation_controller'];
-
// if Flow is enabled on this talk page, overrule talk page red
link
- if ( $occupationController->isTalkpageOccupied( $title ) ) {
+ if ( self::$occupationController->isTalkpageOccupied( $title )
) {
$skname = $template->getSkinName();
$selected = $template->getRequest()->getVal( 'action' )
== 'board-history';
@@ -393,10 +439,8 @@
* @return bool
*/
public static function onAbuseFilterComputeVariable( $method,
AbuseFilterVariableHolder $vars, $parameters, &$result ) {
- $spamfilter = Container::get( 'controller.abusefilter' );
-
// fetch all lazy-load methods
- $methods = $spamfilter->lazyLoadMethods();
+ $methods = self::$abuseFilter->lazyLoadMethods();
// method isn't known here
if ( !isset( $methods[$method] ) ) {
@@ -417,7 +461,7 @@
* @return bool false to abort email notification
*/
public static function onAbortEmailNotification( $editor, $title ) {
- if ( Container::get( 'occupation_controller'
)->isTalkpageOccupied( $title ) ) {
+ if ( self::$occupationController->isTalkpageOccupied( $title )
) {
return false;
}
@@ -425,7 +469,7 @@
}
public static function onInfoAction( IContextSource $ctx, &$pageinfo ) {
- if ( !Container::get( 'occupation_controller'
)->isTalkpageOccupied( $ctx->getTitle() ) ) {
+ if ( !self::$occupationController->isTalkpageOccupied(
$ctx->getTitle() ) ) {
return true;
}
diff --git a/container.php b/container.php
index 3a466d7..016700e 100644
--- a/container.php
+++ b/container.php
@@ -421,20 +421,20 @@
);
} );
-$c['occupation_controller'] = $c->share( function( $c ) {
- global $wgFlowOccupyPages, $wgFlowOccupyNamespaces;
- return new Flow\TalkpageManager( $wgFlowOccupyNamespaces,
$wgFlowOccupyPages );
-} );
+// Initialized in FlowHooks to faciliate only loading the flow container
+// when flow is specifically requested to run. Extension initialization
+// must always happen before calling flow code.
+$c['occupation_controller'] = FlowHooks::getOccupationController();
$c['controller.notification'] = $c->share( function( $c ) {
global $wgContLang;
return new Flow\NotificationController( $wgContLang );
} );
-$c['controller.abusefilter'] = $c->share( function( $c ) {
- global $wgFlowAbuseFilterGroup;
- return new Flow\SpamFilter\AbuseFilter( $c['user'],
$wgFlowAbuseFilterGroup );
-} );
+// Initialized in FlowHooks to faciliate only loading the flow container
+// when flow is specifically requested to run. Extension initialization
+// must always happen before calling flow code.
+$c['controller.abusefilter'] = FlowHooks::getAbuseFilter();
$c['controller.spamregex'] = $c->share( function( $c ) {
return new Flow\SpamFilter\SpamRegex;
diff --git a/includes/Notifications/Controller.php
b/includes/Notifications/Controller.php
index 6be1065..72cd849 100644
--- a/includes/Notifications/Controller.php
+++ b/includes/Notifications/Controller.php
@@ -24,7 +24,7 @@
/**
* Set up Echo notification for Flow extension
*/
- public function setup() {
+ public static function setup() {
global $wgHooks,
$wgEchoNotifications, $wgEchoNotificationIcons,
$wgEchoNotificationCategories;
diff --git a/includes/SpamFilter/Controller.php
b/includes/SpamFilter/Controller.php
index 607c68e..0b42312 100644
--- a/includes/SpamFilter/Controller.php
+++ b/includes/SpamFilter/Controller.php
@@ -20,7 +20,7 @@
* @throws FlowException When provided arguments are not an instance of
SpamFilter
*/
public function __construct( SpamFilter $spamfilter /* [, SpamFilter
$spamfilter2 [, ...]] */ ) {
- $this->spamfilters = func_get_args();
+ $this->spamfilters = array_filter( func_get_args() );
// validate data
foreach ( $this->spamfilters as $spamfilter ) {
--
To view, visit https://gerrit.wikimedia.org/r/115861
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ief1490edd04c82ebe1eab7b13aaa2ba6da78b73f
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits