From: Aryeh Gregor Date: Mon, 23 Jul 2007 19:39:53 +0000 (+0000) Subject: Optimize User::getID() for special cases, and User::isLoggedIn() generally (the latte... X-Git-Tag: 1.31.0-rc.0~51979 X-Git-Url: http://git.cyclocoop.org/%22.%24h.%22?a=commitdiff_plain;h=5ac50ed94d1b2d1199c89f7312609513d85d1e3f;p=lhc%2Fweb%2Fwiklou.git Optimize User::getID() for special cases, and User::isLoggedIn() generally (the latter seems to have always required a database query in the past, when in fact it never should). --- diff --git a/includes/User.php b/includes/User.php index ddbfd23d02..38fd5d0440 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1119,9 +1119,16 @@ class User { /** * Get the user ID. Returns 0 if the user is anonymous or nonexistent. */ - function getID() { - $this->load(); - return $this->mId; + function getID() { + if( $this->mId === null and $this->mName !== null + and User::isIP( $this->mName ) ) { + // Special case, we know the user is anonymous + return 0; + } elseif( $this->mId === null ) { + // Don't load if this was initialized from an ID + $this->load(); + } + return $this->mId; } /** @@ -1715,7 +1722,11 @@ class User { * @return bool */ function isLoggedIn() { - return( $this->getID() != 0 ); + if( $this->mId === null and $this->mName !== null ) { + // Special-case optimization + return !self::isIP( $this->mName ); + } + return $this->getID() != 0; } /**