From: umherirrender Date: Thu, 23 May 2013 18:38:05 +0000 (+0200) Subject: Avoid select/writes for anon user in WatchedItem X-Git-Tag: 1.31.0-rc.0~19597 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=21884f7537d6562a54241469f378229030b5bfa5;p=lhc%2Fweb%2Fwiklou.git Avoid select/writes for anon user in WatchedItem For a page view of a anon user the following select is executed: SELECT wl_notificationtimestamp FROM `watchlist` WHERE wl_user = '0' AND wl_namespace = '0' AND wl_title = 'Hauptseite' LIMIT 1 Change-Id: I1cf77a2d024956ed7c150bdf1687eb80c7eccc6f --- diff --git a/includes/WatchedItem.php b/includes/WatchedItem.php index 01376a09d1..45aa82266e 100644 --- a/includes/WatchedItem.php +++ b/includes/WatchedItem.php @@ -89,6 +89,12 @@ class WatchedItem { } $this->loaded = true; + // Only loggedin user can have a watchlist + if ( $this->mUser->isAnon() ) { + $this->watched = false; + return; + } + # Pages and their talk pages are considered equivalent for watching; # remember that talk namespaces are numbered as page namespace+1. @@ -135,6 +141,11 @@ class WatchedItem { * page is not watched or the notification timestamp is already NULL. */ public function resetNotificationTimestamp( $force = '' ) { + // Only loggedin user can have a watchlist + if ( wfReadOnly() || $this->mUser->isAnon() ) { + return; + } + if ( $force != 'force' ) { $this->load(); if ( !$this->watched || $this->timestamp === null ) { @@ -153,11 +164,17 @@ class WatchedItem { /** * Given a title and user (assumes the object is setup), add the watch to the * database. - * @return bool (always true) + * @return bool */ public function addWatch() { wfProfileIn( __METHOD__ ); + // Only loggedin user can have a watchlist + if ( wfReadOnly() || $this->mUser->isAnon() ) { + wfProfileOut( __METHOD__ ); + return false; + } + // Use INSERT IGNORE to avoid overwriting the notification timestamp // if there's already an entry for this page $dbw = wfGetDB( DB_MASTER ); @@ -192,6 +209,12 @@ class WatchedItem { public function removeWatch() { wfProfileIn( __METHOD__ ); + // Only loggedin user can have a watchlist + if ( wfReadOnly() || $this->mUser->isAnon() ) { + wfProfileOut( __METHOD__ ); + return false; + } + $success = false; $dbw = wfGetDB( DB_MASTER ); $dbw->delete( 'watchlist',