Krinkle has uploaded a new change for review. https://gerrit.wikimedia.org/r/201403
Change subject: User: Optimise isAnon/isLoggedIn by not loading user ...................................................................... User: Optimise isAnon/isLoggedIn by not loading user Inspired by rational left in comment for wfLogProfilingData() at https://gerrit.wikimedia.org/r/#/c/201375/1/includes/GlobalFunctions.php. Resolves FIXME from r74934 (d09f081aa). Change-Id: I78696709f527f6005eb7a1dca64e7f6ce4ead31e --- M includes/User.php 1 file changed, 28 insertions(+), 17 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/03/201403/1 diff --git a/includes/User.php b/includes/User.php index 2e88978..4d22ef1 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1976,11 +1976,38 @@ } /** + * Fast check whether the User has a name that isn't an IP address. + * + * @since 1.25 + * @return boolean + */ + protected function hasUserName() { + return $this->mId !== null || ( $this->mName !== null && !User::isIP( $this->mName ) ); + } + + /** + * Get whether the user is logged in + * @return bool + */ + public function isLoggedIn() { + // Don't load the user merely to check whether they're logged-in + return $this->hasUserName(); + } + + /** + * Get whether the user is anonymous + * @return bool + */ + public function isAnon() { + return !$this->isLoggedIn(); + } + + /** * Get the user's ID. * @return int The user's ID; 0 if the user is anonymous or nonexistent */ public function getId() { - if ( $this->mId === null && $this->mName !== null && User::isIP( $this->mName ) ) { + if ( !$this->hasUserName() ) { // Special case, we know the user is anonymous return 0; } elseif ( !$this->isItemLoaded( 'id' ) ) { @@ -3166,22 +3193,6 @@ $this->invalidateCache(); return true; - } - - /** - * Get whether the user is logged in - * @return bool - */ - public function isLoggedIn() { - return $this->getID() != 0; - } - - /** - * Get whether the user is anonymous - * @return bool - */ - public function isAnon() { - return !$this->isLoggedIn(); } /** -- To view, visit https://gerrit.wikimedia.org/r/201403 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I78696709f527f6005eb7a1dca64e7f6ce4ead31e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Krinkle <krinklem...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits