From 1a453971a3da1afb86b1df0ef2276c9c2c7cd717 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Wed, 16 Jan 2019 23:25:46 +0100 Subject: [PATCH] Try to avoid master queries for GET requests 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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php index e31bc06b56..7a2679e4c8 100644 --- a/includes/skins/Skin.php +++ b/includes/skins/Skin.php @@ -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() ) ) { -- 2.20.1