From cd3db788a9dc17dacbf935b66f301c5e2a4d51dc Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 11 Aug 2009 09:16:34 +0000 Subject: [PATCH] BUGFIX: Performance improvement to Member::currentUserID() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84167 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- security/Member.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/security/Member.php b/security/Member.php index bf625197a..3a1a46a73 100644 --- a/security/Member.php +++ b/security/Member.php @@ -264,6 +264,9 @@ class Member extends DataObject { * auto-login. */ static function autoLogin() { + // Don't bother trying this multiple times + self::$_already_tried_to_auto_log_in = true; + if(strpos(Cookie::get('alc_enc'), ':') && !Session::get("loggedInAs")) { list($uid, $token) = explode(':', Cookie::get('alc_enc'), 2); $SQL_uid = Convert::raw2sql($uid); @@ -411,12 +414,7 @@ class Member extends DataObject { * user or FALSE. */ static function currentUser() { - $id = Session::get("loggedInAs"); - if(!$id) { - self::autoLogin(); - $id = Session::get("loggedInAs"); - } - + $id = Member::currentUserID(); if($id) { return DataObject::get_one("Member", "\"Member\".\"ID\" = $id"); } @@ -430,13 +428,14 @@ class Member extends DataObject { */ static function currentUserID() { $id = Session::get("loggedInAs"); - if(!$id) { + if(!$id && !self::$_already_tried_to_auto_log_in) { self::autoLogin(); $id = Session::get("loggedInAs"); } return is_numeric($id) ? $id : 0; } + private static $_already_tried_to_auto_log_in = false; /*