Try to avoid master queries for GET requests
authorDaimona Eaytoy <daimona.wiki@gmail.com>
Wed, 16 Jan 2019 22:25:46 +0000 (23:25 +0100)
committerDaimona Eaytoy <daimona.wiki@gmail.com>
Wed, 16 Jan 2019 22:25:46 +0000 (23:25 +0100)
Skin::getUndeleteLink performs several checks, including a
Title::userCan, which in turn checks the blocked status from master in
order to decide whether to show the link. This happens during GET
requests, and a basic calculation shows that it is responsible for
roughly 15% of the DBPerformance alerts.
This patch rearranges the IF conditions so that the permission check is
performed last, and thus will be avoided if the previous condition is
false.

Change-Id: I45a18a244a26df09beb12e198e0e91a465bd1907

includes/skins/Skin.php

index e31bc06..7a2679e 100644 (file)
@@ -716,10 +716,12 @@ abstract class Skin extends ContextSource {
         */
        function getUndeleteLink() {
                $action = $this->getRequest()->getVal( 'action', 'view' );
+               $title = $this->getTitle();
 
-               if ( $this->getTitle()->userCan( 'deletedhistory', $this->getUser() ) &&
-                       ( !$this->getTitle()->exists() || $action == 'history' ) ) {
-                       $n = $this->getTitle()->isDeleted();
+               if ( ( !$title->exists() || $action == 'history' ) &&
+                       $title->userCan( 'deletedhistory', $this->getUser() )
+               ) {
+                       $n = $title->isDeleted();
 
                        if ( $n ) {
                                if ( $this->getTitle()->quickUserCan( 'undelete', $this->getUser() ) ) {