Distinguish read vs write mode Action classes
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 14 Jan 2016 00:06:06 +0000 (16:06 -0800)
committerOri.livneh <ori@wikimedia.org>
Fri, 15 Jan 2016 01:13:38 +0000 (01:13 +0000)
Bug: T123589
Change-Id: I3c8fab646d3bb8cd468e5b60c27f3c5d43f9f97c

14 files changed:
includes/MediaWiki.php
includes/actions/Action.php
includes/actions/DeleteAction.php
includes/actions/EditAction.php
includes/actions/FormAction.php
includes/actions/MarkpatrolledAction.php
includes/actions/ProtectAction.php
includes/actions/PurgeAction.php
includes/actions/RevertAction.php
includes/actions/RevisiondeleteAction.php
includes/actions/RollbackAction.php
includes/actions/UnprotectAction.php
includes/actions/UnwatchAction.php
includes/actions/WatchAction.php

index 6a57d39..ab02ba7 100644 (file)
@@ -458,7 +458,6 @@ class MediaWiki {
         * @param Title $requestTitle The original title, before any redirects were applied
         */
        private function performAction( Page $page, Title $requestTitle ) {
-
                $request = $this->context->getRequest();
                $output = $this->context->getOutput();
                $title = $this->context->getTitle();
@@ -471,10 +470,16 @@ class MediaWiki {
                }
 
                $act = $this->getAction();
-
                $action = Action::factory( $act, $page, $this->context );
 
                if ( $action instanceof Action ) {
+                       // Narrow DB query expectations for this HTTP request
+                       $trxLimits = $this->config->get( 'TrxProfilerLimits' );
+                       $trxProfiler = Profiler::instance()->getTransactionProfiler();
+                       if ( $request->wasPosted() && !$action->doesWrites() ) {
+                               $trxProfiler->setExpectations( $trxLimits['POST-nonwrite'], __METHOD__ );
+                       }
+
                        # Let CDN cache things if we can purge them.
                        if ( $this->config->get( 'UseSquid' ) &&
                                in_array(
@@ -494,7 +499,6 @@ class MediaWiki {
                        $output->setStatusCode( 404 );
                        $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
                }
-
        }
 
        /**
@@ -625,7 +629,7 @@ class MediaWiki {
        }
 
        private function main() {
-               global $wgTitle, $wgTrxProfilerLimits;
+               global $wgTitle;
 
                $request = $this->context->getRequest();
 
@@ -649,13 +653,14 @@ class MediaWiki {
                $action = $this->getAction();
                $wgTitle = $title;
 
+               // Set DB query expectations for this HTTP request
+               $trxLimits = $this->config->get( 'TrxProfilerLimits' );
                $trxProfiler = Profiler::instance()->getTransactionProfiler();
                $trxProfiler->setLogger( LoggerFactory::getInstance( 'DBPerformance' ) );
-
                if ( $request->wasPosted() ) {
-                       $trxProfiler->setExpectations( $wgTrxProfilerLimits['POST'], __METHOD__ );
+                       $trxProfiler->setExpectations( $trxLimits['POST'], __METHOD__ );
                } else {
-                       $trxProfiler->setExpectations( $wgTrxProfilerLimits['GET'], __METHOD__ );
+                       $trxProfiler->setExpectations( $trxLimits['GET'], __METHOD__ );
                }
 
                // If the user has forceHTTPS set to true, or if the user
index 6ddc596..97d7132 100644 (file)
@@ -417,4 +417,13 @@ abstract class Action {
                        wfTransactionalTimeLimit();
                }
        }
+
+       /**
+        * Indicates whether this action may perform database writes
+        * @return bool
+        * @since 1.27
+        */
+       public function doesWrites() {
+               return false;
+       }
 }
index 841a94d..cb57d3e 100644 (file)
@@ -53,4 +53,8 @@ class DeleteAction extends FormlessAction {
                $this->addHelpLink( 'Help:Sysop deleting and undeleting' );
                $this->page->delete();
        }
+
+       public function doesWrites() {
+               return true;
+       }
 }
index eb53f19..643d1c4 100644 (file)
@@ -58,4 +58,8 @@ class EditAction extends FormlessAction {
                        $editor->edit();
                }
        }
+
+       public function doesWrites() {
+               return true;
+       }
 }
index aa201d7..55b9b99 100644 (file)
@@ -127,4 +127,8 @@ abstract class FormAction extends Action {
                        $this->onSuccess();
                }
        }
+
+       public function doesWrites() {
+               return true;
+       }
 }
index 34067f1..b8a7616 100644 (file)
@@ -89,4 +89,8 @@ class MarkpatrolledAction extends FormlessAction {
                $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
                $this->getOutput()->returnToMain( null, $return );
        }
+
+       public function doesWrites() {
+               return true;
+       }
 }
index 48909cf..126daa0 100644 (file)
@@ -51,4 +51,8 @@ class ProtectAction extends FormlessAction {
 
                $this->page->protect();
        }
+
+       public function doesWrites() {
+               return true;
+       }
 }
index 7e77846..183c3b9 100644 (file)
@@ -97,4 +97,8 @@ class PurgeAction extends FormAction {
        public function onSuccess() {
                $this->getOutput()->redirect( $this->getTitle()->getFullURL( $this->redirectParams ) );
        }
+
+       public function doesWrites() {
+               return true;
+       }
 }
index 4885a31..8a54c39 100644 (file)
@@ -151,4 +151,8 @@ class RevertAction extends FormAction {
        protected function getDescription() {
                return OutputPage::buildBacklinkSubtitle( $this->getTitle() );
        }
+
+       public function doesWrites() {
+               return true;
+       }
 }
index dbcb848..7df42b3 100644 (file)
@@ -58,4 +58,8 @@ class RevisiondeleteAction extends FormlessAction {
                $special->getContext()->setTitle( $special->getPageTitle() );
                $special->run( '' );
        }
+
+       public function doesWrites() {
+               return true;
+       }
 }
index 0404856..cc94fd3 100644 (file)
@@ -126,4 +126,8 @@ class RollbackAction extends FormlessAction {
        protected function getDescription() {
                return '';
        }
+
+       public function doesWrites() {
+               return true;
+       }
 }
index 559cfaf..0757e88 100644 (file)
@@ -39,4 +39,8 @@ class UnprotectAction extends ProtectAction {
        public function show() {
                $this->page->unprotect();
        }
+
+       public function doesWrites() {
+               return true;
+       }
 }
index 0a8628d..f8f1dc1 100644 (file)
@@ -52,4 +52,8 @@ class UnwatchAction extends WatchAction {
        public function onSuccess() {
                $this->getOutput()->addWikiMsg( 'removedwatchtext', $this->getTitle()->getPrefixedText() );
        }
+
+       public function doesWrites() {
+               return true;
+       }
 }
index 30b83d7..547fd9b 100644 (file)
@@ -178,4 +178,8 @@ class WatchAction extends FormAction {
        public static function getUnwatchToken( Title $title, User $user, $action = 'unwatch' ) {
                return self::getWatchToken( $title, $user, $action );
        }
+
+       public function doesWrites() {
+               return true;
+       }
 }