From 5ac50ed94d1b2d1199c89f7312609513d85d1e3f Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Mon, 23 Jul 2007 19:39:53 +0000 Subject: [PATCH] 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). --- includes/User.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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; } /** -- 2.20.1