From 6d1b3901df51f372c13883f4e779cc574567f2eb Mon Sep 17 00:00:00 2001 From: Tom Rix Date: Mon, 1 Mar 2010 02:56:58 +0000 Subject: [PATCH] ENHANCEMENT: Be more specific about when the permission cache is flushed, so that the CMS can be more efficient. (from r83435) --- code/Subsite.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/code/Subsite.php b/code/Subsite.php index 06a902f..73fb7e1 100644 --- a/code/Subsite.php +++ b/code/Subsite.php @@ -219,7 +219,7 @@ JS; $id = Session::get('SubsiteID'); } - if(!isset($id) || $id === NULL) { + if($id === NULL) { $id = self::getSubsiteIDForDomain(); Session::set('SubsiteID', $id); } @@ -247,11 +247,13 @@ JS; static function changeSubsite($subsite) { if(is_object($subsite)) $subsiteID = $subsite->ID; else $subsiteID = $subsite; - - Session::set('SubsiteID', $subsiteID); - - // And clear caches - Permission::flush_permission_cache() ; + + Session::set('SubsiteID', (int)$subsiteID); + + // Only bother flushing caches if we've actually changed + if($subsiteID != self::currentSubsiteID()) { + Permission::flush_permission_cache(); + } } /** @@ -291,6 +293,9 @@ JS; if(sizeof($subsiteIDs) > 1) user_error("Multiple subsites match '$host'", E_USER_WARNING); return $subsiteIDs[0]; } + + // Default subsite id = 0, the main site + return 0; } function getMembersByPermission($permissionCodes = array('ADMIN')){